1
1
mirror of https://gitlab.archlinux.org/archlinux/infrastructure.git synced 2025-01-18 08:06:16 +01:00
infrastructure/roles/archbuild/files/clean-chroots
Jan Alexander Steffens (heftig) 58c5d9116c
clean-chroots: Recurse, like devtools' subvolume_delete_recursive does
Needed to get rid of subvolumes created by tmpfiles.
2020-05-06 13:04:00 +02:00

54 lines
857 B
Bash
Executable File

#!/bin/zsh
setopt extendedglob nomatch errreturn
integer ret=0
cd /var/lib/archbuild
chroots=( */^root(/Nmh+2) )
(( ${#chroots} )) || exit 0
df -HT .
echo "<6>Deleting ${#chroots} chroots"
if btrfs filesystem df . &>/dev/null; then
remove() {
local subvol
test -d $1
find $1 -mindepth 1 -xdev -depth -inum 256 -print0 |
while IFS= read -d $'\0' -r subvol; do
remove $subvol
done
btrfs sub del -- $1 &>/dev/null
}
else
remove() {
rm -rf -- $1
}
fi
for chroot in $chroots; do
exec 9>>| $chroot.lock
if ! flock -n 9; then
echo "<5>Not deleting $chroot; in use"
continue
fi
if remove $chroot; then
echo "<6>Deleted $chroot"
else
echo "<3>Error deleting $chroot"
ret=1
fi
# We don't remove the lockfile. Less races that way
done
df -HT .
exit $ret
# vim:set sw=2 et: