Browse code

nuke-graph-directory.sh: Improve subvolume search

This change allows btrfs subvolumes to be found in additional system
configurations. The old logic failed to correctly identify subvolumes
when the root fs was mounted as a subvolume that was not the btrfs
filesystem root.

Signed-off-by: Adam Mills <adam@armills.info>

Adam Mills authored on 2016/07/29 03:25:20
Showing 1 changed files
... ...
@@ -51,13 +51,10 @@ done
51 51
 
52 52
 # now, let's go destroy individual btrfs subvolumes, if any exist
53 53
 if command -v btrfs > /dev/null 2>&1; then
54
-	root="$(df "$dir" | awk 'NR>1 { print $NF }')"
55
-	root="${root%/}" # if root is "/", we want it to become ""
56
-	for subvol in $(btrfs subvolume list -o "$root/" 2>/dev/null | awk -F' path ' '{ print $2 }' | sort -r); do
57
-		subvolDir="$root/$subvol"
58
-		if dir_in_dir "$subvolDir" "$dir"; then
59
-			( set -x; btrfs subvolume delete "$subvolDir" )
60
-		fi
54
+	# Find btrfs subvolumes under $dir checking for inode 256
55
+	# Source: http://stackoverflow.com/a/32865333
56
+	for subvol in $(find "$dir" -type d -inum 256 | sort -r); do
57
+		( set -x; btrfs subvolume delete "$subvol" )
61 58
 	done
62 59
 fi
63 60