Skip to content

ENT-13025: Switched from ls to find to determine if directory is empty #1734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packaging/common/cfengine-hub/preinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down