From 2d3827b12d0eda00f28147905ea579d3d07df02c Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 17 Apr 2019 13:47:54 +0200 Subject: lib/common-functions: recursively_umount_and_rm(): copy stuff from archlinux/devtool's lib/archroot.sh: is_subvolume(), is_same_fs() and subvolume_delete_recursive() - now it should do the correct thing on btrfs, too --- lib/common-functions | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/common-functions') diff --git a/lib/common-functions b/lib/common-functions index e87e6ef..17309fb 100755 --- a/lib/common-functions +++ b/lib/common-functions @@ -390,10 +390,25 @@ recursively_umount_and_rm() { exit 42 fi + # the sh -c '...' construct branch below is borrowed from + # archlinux/devtools lib/archroot.sh: is_subvolume(), is_same_fs() and + # subvolume_delete_recursive() + # shellcheck disable=SC1004,SC2016 find "${dir}" \ - -xdev -depth -type d \ + -depth \ + -xdev \ + -type d \ -exec 'mountpoint' '-q' '{}' ';' \ - -exec 'sudo' 'umount' '-l' '{}' ';' + -exec 'sudo' 'umount' '-l' '{}' ';' \ + -prune \ + , \ + -inum 256 \ + -exec sh -c ' + [ "$(stat -f -c %T "$1")" = btrfs ] && \ + [ "$(stat -c %d "$1")" = "$2" ] + ' {} "$(stat -c %d "${dir}")" \; \ + -exec btrfs subvolume delete {} \; \ + -prune rm -rf --one-file-system "${dir}" } -- cgit v1.2.3-54-g00ecf