diff --git a/lib/archroot.sh b/lib/archroot.sh index 46d49639e1084b1313dc073ad41c23e24159c08d..87c28a225bd5f38d30bb472f087c286637e6ee96 100644 --- a/lib/archroot.sh +++ b/lib/archroot.sh @@ -24,6 +24,15 @@ is_btrfs() { [[ -e "$1" && "$(stat -f -c %T "$1")" == 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 ) # @@ -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 72b7eb7b3dc2e6a9f2a19955ff4f11bb7fb10868..88c2cdc137654d402d2d1f0deabf3738b9267199 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