diff options
author | Erich Eckner <git@eckner.net> | 2019-04-17 13:47:54 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-04-17 13:47:54 +0200 |
commit | 2d3827b12d0eda00f28147905ea579d3d07df02c (patch) | |
tree | 56ab7dcf09d180f4b1fc08d88d9abd4167e7edb4 | |
parent | 254a31c2e10b3b806a3b00137d32acf24af77a44 (diff) | |
download | builder-2d3827b12d0eda00f28147905ea579d3d07df02c.tar.xz |
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
-rwxr-xr-x | lib/common-functions | 19 |
1 files changed, 17 insertions, 2 deletions
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}" } |