summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2017-03-07 19:55:05 +0100
committerJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2017-03-07 20:37:54 +0100
commitc53a3e80170dc9d45beeeb623edfbf0bd40799a7 (patch)
tree6cbeab8af72dfa40a7c445817fe208583df7e872
parent45f87aa9d5b44e4ff2f73be6597d4024bcded8e3 (diff)
downloaddevtools-c53a3e80170dc9d45beeeb623edfbf0bd40799a7.tar.gz
devtools-c53a3e80170dc9d45beeeb623edfbf0bd40799a7.tar.xz
lib/archroot.sh: Add is_btrfs helper
-rw-r--r--archbuild.in2
-rw-r--r--lib/archroot.sh8
-rw-r--r--makechrootpkg.in7
-rw-r--r--mkarchroot.in2
4 files changed, 12 insertions, 7 deletions
diff --git a/archbuild.in b/archbuild.in
index 4fb33c3..b192788 100644
--- a/archbuild.in
+++ b/archbuild.in
@@ -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}"
diff --git a/lib/archroot.sh b/lib/archroot.sh
index 7d7ab67..14417aa 100644
--- a/lib/archroot.sh
+++ b/lib/archroot.sh
@@ -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 ]]
+}
diff --git a/makechrootpkg.in b/makechrootpkg.in
index 695b898..9e84996 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -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
diff --git a/mkarchroot.in b/mkarchroot.in
index 010de3c..3d7e396 100644
--- a/mkarchroot.in
+++ b/mkarchroot.in
@@ -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"