summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2017-04-10 13:08:33 -0400
committerLuke Shumaker <lukeshu@parabola.nu>2017-04-16 23:20:29 -0400
commitd209a589f690723e5aa14f94a3b5c57222f31c54 (patch)
treecb88b7b5063bc6a97c8ee3f2bf6187ae9ee398b5
parent49088b0860276c664933c2b3e36a2fef714b7a07 (diff)
downloaddevtools32-d209a589f690723e5aa14f94a3b5c57222f31c54.tar.xz
makechrootpkg: delete_chroot: Fix the is-btrfs-subvolume check.
First of all, it ran `is_btrfs "$chrootdir"` to decide if it was on btrfs, but $chrootdir wasn't defined locally; it just happens to work because $chrootdir was defined in main(). (I noticed this because in Parabola, it is called differently, so $chrootdir was empty). So I was tempted to just change it to `is_btrfs "$copydir"`, but if $copydir is just a regular directory on a btrfs filesystem, then it It would leave much of $copydir intact. What we really care about is if $copydir is a btrfs subvolume; which we can check by combining the is_btrfs check with inspecting the inum of the directory. I put this combined check in lib/archroot.sh:is_subvolume. https://lists.archlinux.org/pipermail/arch-projects/2013-September/003901.html
-rw-r--r--lib/archroot.sh11
-rw-r--r--makechrootpkg.in2
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/archroot.sh b/lib/archroot.sh
index 46d4963..87c28a2 100644
--- a/lib/archroot.sh
+++ b/lib/archroot.sh
@@ -25,6 +25,15 @@ is_btrfs() {
}
##
+# usage : is_subvolume( $path )
+# return : whether $path is a the root of a btrfs subvolume (including
+# the top-level subvolume).
+##
+is_subvolume() {
+ [[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs && "$(stat -c %i "$1")" == 256 ]]
+}
+
+##
# usage : subvolume_delete_recursive( $path )
#
# Find all btrfs subvolumes under and including $path and delete them.
@@ -32,7 +41,7 @@ is_btrfs() {
subvolume_delete_recursive() {
local subvol
- is_btrfs "$1" || return 0
+ is_subvolume "$1" || return 0
while IFS= read -d $'\0' -r subvol; do
if ! btrfs subvolume delete "$subvol" &>/dev/null; then
diff --git a/makechrootpkg.in b/makechrootpkg.in
index 72b7eb7..88c2cdc 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -144,7 +144,7 @@ delete_chroot() {
local copy=${1:-$2}
stat_busy "Removing chroot copy [%s]" "$copy"
- if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
+ if is_subvolume "$copydir" && ! mountpoint -q "$copydir"; then
subvolume_delete_recursive "$copydir" ||
die "Unable to delete subvolume %s" "$copydir"
else