improve btrfs handling devtools patches
This commit is contained in:
parent
c7f309fda3
commit
aafafbeab0
4 changed files with 30 additions and 15 deletions
|
@ -81,7 +81,7 @@ umask 0022
|
|||
|
||||
lock 9 "${working_dir}.lock" "Locking chroot"
|
||||
|
||||
if [[ $(stat -f -c %T "$working_dir") == btrfs ]]; then
|
||||
if is_btrfs "$working_dir"; then
|
||||
rmdir "$working_dir"
|
||||
if ! btrfs subvolume create "$working_dir"; then
|
||||
die "Couldn't create subvolume for '%s'" "$working_dir"
|
||||
|
|
|
@ -128,11 +128,9 @@ create_chroot() {
|
|||
slock 8 "$chrootdir/root.lock" "Locking clean chroot"
|
||||
|
||||
stat_busy "Creating clean working copy [$copy]"
|
||||
if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then
|
||||
if [[ -d $copydir ]]; then
|
||||
btrfs subvolume delete "$copydir" >/dev/null ||
|
||||
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
|
||||
subvolume_delete_recursive "$copydir" ||
|
||||
die "Unable to delete subvolume %s" "$copydir"
|
||||
fi
|
||||
btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null ||
|
||||
die "Unable to create subvolume %s" "$copydir"
|
||||
else
|
||||
|
@ -151,7 +149,7 @@ create_chroot() {
|
|||
|
||||
clean_temporary() {
|
||||
stat_busy "Removing temporary copy [$copy]"
|
||||
if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then
|
||||
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
|
||||
btrfs subvolume delete "$copydir" >/dev/null ||
|
||||
die "Unable to delete subvolume %s" "$copydir"
|
||||
else
|
||||
|
|
|
@ -209,9 +209,7 @@ chroot_clean(){
|
|||
|
||||
lock 9 "${copy}.lock" "Locking chroot copy '${copy}'"
|
||||
|
||||
if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then
|
||||
{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
|
||||
fi
|
||||
subvolume_delete_recursive "${copy}"
|
||||
rm -rf --one-file-system "${copy}"
|
||||
done
|
||||
exec 9>&-
|
||||
|
|
19
lib/util.sh
19
lib/util.sh
|
@ -760,3 +760,22 @@ run(){
|
|||
$1 $2
|
||||
fi
|
||||
}
|
||||
|
||||
is_btrfs() {
|
||||
[[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]]
|
||||
}
|
||||
|
||||
subvolume_delete_recursive() {
|
||||
local subvol
|
||||
|
||||
is_btrfs "$1" || return 0
|
||||
|
||||
while IFS= read -d $'\0' -r subvol; do
|
||||
if ! btrfs subvolume delete "$subvol" &>/dev/null; then
|
||||
error "Unable to delete subvolume %s" "$subvol"
|
||||
return 1
|
||||
fi
|
||||
done < <(find "$1" -xdev -depth -inum 256 -print0)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue