lib/archroot.sh: Add is_btrfs helper

This commit is contained in:
Jan Alexander Steffens (heftig) 2017-03-07 19:55:05 +01:00
parent 45f87aa9d5
commit c53a3e8017
No known key found for this signature in database
GPG Key ID: A5E9288C4FA415FA
4 changed files with 12 additions and 7 deletions

View File

@ -52,7 +52,7 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
lock 9 "$copy.lock" "Locking chroot copy '$copy'"
if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then
if is_btrfs "${copy}"; then
{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
fi
rm -rf --one-file-system "${copy}"

View File

@ -12,3 +12,11 @@ check_root() {
exec su root -c "$(printf ' %q' "${orig_argv[@]}")"
fi
}
##
# usage : is_btrfs( $path )
# return : whether $path is on a btrfs
##
is_btrfs() {
[[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]]
}

View File

@ -96,7 +96,7 @@ 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 is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
if [[ -d $copydir ]]; then
btrfs subvolume delete "$copydir" >/dev/null ||
die "Unable to delete subvolume %s" "$copydir"
@ -119,7 +119,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
@ -285,9 +285,6 @@ chrootdir=$(readlink -e "$passeddir")
[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir"
[[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir"
# Detect chrootdir filesystem type
chroottype=$(stat -f -c %T "$chrootdir")
if [[ ${copy:0:1} = / ]]; then
copydir=$copy
else

View File

@ -57,7 +57,7 @@ mkdir -p "$working_dir"
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"