diff --git a/makechrootpkg.in b/makechrootpkg.in index 284d444..0da321b 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -91,6 +91,13 @@ create_chroot() { stat_busy "Creating clean working copy [$copy]" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then if [[ -d $copydir ]]; then + local IFS=$'\n' + local subvlist=($(btrfs subvolume list --sort=-rootid -o "$copydir")) || + die "Unable to list subvolumes below %s" "$copydir" + for subv in ${subvlist[@]}; do + btrfs subvolume delete "/${subv##*' '}" >/dev/null || + die "Unable to delete subvolume %s" "/${subv##*' '}" + done btrfs subvolume delete "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir" fi @@ -113,6 +120,13 @@ create_chroot() { clean_temporary() { stat_busy "Removing temporary copy [$copy]" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then + local IFS=$'\n' + local subvlist=($(btrfs subvolume list --sort=-rootid -o "$copydir")) || + die "Unable to list subvolumes below %s" "$copydir" + for subv in ${subvlist[@]}; do + btrfs subvolume delete "/${subv##*' '}" >/dev/null || + die "Unable to delete subvolume %s" "/${subv##*' '}" + done btrfs subvolume delete "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir" else