Skip to content

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

Open
nickanderson wants to merge 1 commit into
cfengine:masterfrom
nickanderson:ENT-13025/master
Open

ENT-13025: Switched from ls to find to determine if directory is empty#1734
nickanderson wants to merge 1 commit into
cfengine:masterfrom
nickanderson:ENT-13025/master

Conversation

@nickanderson
Copy link
Copy Markdown
Member

Ticket: ENT-13025

@olehermanse olehermanse requested a review from larsewi June 3, 2025 11:29
Ticket: ENT-13025
Changelog: Fixed case where upgrade is aborted when BACKUP_DIR is empty
@nickanderson
Copy link
Copy Markdown
Member Author

Just came across this old pr thats been aproved since june 2025 I see the ticket itself was rejected. @larsewi @craigcomstock do you want this change ?

# 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the advantage? I don't see why this is better.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that find is probably better but it is not more readable. For that I might suggest

if [ "$(du -a "$BACKUP_DIR" | wc -l)" -gt "1" ]; then

du (disk usage) is an old-timer but does make some sense and hopefully is stable. :p

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Marking this PR as stale due to inactivity; it will be closed in 7 days.

@github-actions github-actions Bot added the stale label Jun 1, 2026
Copy link
Copy Markdown
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ls command is known to be unreliable across different implementations. However, in this case it does not really matter, since we are not actually trying to parse the output.

PRO: this would silence a shellcheck warning. CON: slightly less readable.

@github-actions github-actions Bot removed the stale label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants