From 7658aa54fc0dd81e6df54c7757191e4482c4fa7c Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Mon, 2 Jun 2025 16:08:10 -0500 Subject: [PATCH] Switched from ls to find to determine if directory is empty Ticket: ENT-13025 Changelog: Fixed case where upgrade is aborted when BACKUP_DIR is empty --- packaging/common/cfengine-hub/preinstall.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packaging/common/cfengine-hub/preinstall.sh b/packaging/common/cfengine-hub/preinstall.sh index b4b1ff771..0c199c199 100644 --- a/packaging/common/cfengine-hub/preinstall.sh +++ b/packaging/common/cfengine-hub/preinstall.sh @@ -24,13 +24,15 @@ fi test -z "$BACKUP_DIR" && BACKUP_DIR=$PREFIX/state/pg/backup -if [ -d "$BACKUP_DIR" ] && [ -n "$(ls -A "$BACKUP_DIR")" ]; then - # If the backup directory exists and is not empty we don't want to proceed, - # that stale data can cause database migration problems. - cf_console echo "Backup directory $BACKUP_DIR exists and is not empty." - cf_console echo 'Please remove it, clean it, or set a different directory by setting a BACKUP_DIR env variable, like this:' - cf_console echo 'export BACKUP_DIR=/mnt/plenty-of-free-space' - exit 1 +# If the backup directory exists inspect it more closely +if [ -d "$BACKUP_DIR" ]; then + # If the backup directory is not empty we don't want to continue. + if find "$BACKUP_DIR" -maxdepth 1 -mindepth 1 -print -quit | grep -q .; then + cf_console echo "Backup directory $BACKUP_DIR exists and is not empty." + cf_console echo 'Please remove it, clean it, or set a different directory by setting a BACKUP_DIR env variable, like this:' + cf_console echo 'export BACKUP_DIR=/mnt/plenty-of-free-space' + exit 1 + fi fi if migrating_postgres; then