Skip to content
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

Fixes subvol delete on a non-btrfs volume #42272

Merged
merged 2 commits into from
Apr 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions contrib/nuke-graph-directory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ if command -v btrfs > /dev/null 2>&1; then
# Source: http://stackoverflow.com/a/32865333
for subvol in $(find "$dir" -type d -inum 256 | sort -r); do
if [ "$dir" != "$subvol" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

Oh, it's probably worth bringing that conditinoal all the way up to here, ala:

Suggested change
if [ "$dir" != "$subvol" ]; then
if [ "$dir" != "$subvol" ] && subvolType="$(stat -f --format=%T "$subvol")" && [ "$subvolType" = "btrfs" ]; then

(So we only have a single if)

Copy link
Author

Choose a reason for hiding this comment

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

that's, nifty; and looks good to me.

(
set -x
btrfs subvolume delete "$subvol"
)
if [ "$(stat -f --format=%T $subvol)" == "btrfs" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

I realize this script specified bash, but I know we try to stay close to POSIX where possible, to allow running scripts in non-bash environments; perhaps change this to;

Suggested change
if [ "$(stat -f --format=%T $subvol)" == "btrfs" ]; then
if [ "$(stat -f --format=%T $subvol)" = "btrfs" ]; then

Copy link
Member

Choose a reason for hiding this comment

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

Full agreement from me 😇

I'd go one step further, too:

Suggested change
if [ "$(stat -f --format=%T $subvol)" == "btrfs" ]; then
if [ "$(stat -f --format=%T "$subvol")" = "btrfs" ]; then

Or even (to catch any possible failing exit code from stat):

Suggested change
if [ "$(stat -f --format=%T $subvol)" == "btrfs" ]; then
if subvolType="$(stat -f --format=%T "$subvol")" && [ "$subvolType" = "btrfs" ]; then

(
set -x
btrfs subvolume delete "$subvol"
)
fi
fi
done
fi
Expand Down