index : devtools32 | |
Archlinux32 fork of devtools | gitolite user |
summaryrefslogtreecommitdiff |
author | Luke Shumaker <lukeshu@parabola.nu> | 2017-05-05 18:41:00 -0400 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2017-07-14 06:54:28 +0200 |
commit | e9e3fc8b50b1b492f0ee77bd503a729bfc2c98fe (patch) | |
tree | c92e5574dc7bf11a536a043011bb4e7f272c2c89 /makechrootpkg.in | |
parent | 89e08408ff3e28268a992c5279713c8cf44d7eef (diff) |
-rw-r--r-- | makechrootpkg.in | 32 |
diff --git a/makechrootpkg.in b/makechrootpkg.in index 9a77441..53235ee 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -98,31 +98,37 @@ load_vars() { return 0 } -# Usage: sync_chroot $chrootdir $copydir [$copy] +# Usage: sync_chroot $rootdir $copydir [$copy] sync_chroot() { - local chrootdir=$1 + local rootdir=$1 local copydir=$2 local copy=${3:-$2} - if [[ "$chrootdir/root" -ef "$copydir" ]]; then + if [[ "$rootdir" -ef "$copydir" ]]; then error 'Cannot sync copy with itself: %s' "$copydir" return 1 fi # Get a read lock on the root chroot to make # sure we don't clone a half-updated chroot - slock 8 "$chrootdir/root.lock" \ - "Locking clean chroot [%s]" "$chrootdir/root" - - stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copy" - if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then - subvolume_delete_recursive "$copydir" || - die "Unable to delete subvolume %s" "$copydir" - btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null || + slock 8 "$rootdir.lock" \ + "Locking clean chroot [%s]" "$rootdir" + + stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$rootdir" "$copy" + if is_subvolume "$rootdir" && is_same_fs "$rootdir" "$(dirname -- "$copydir")" && ! mountpoint -q "$copydir"; then + if is_subvolume "$copydir"; then + subvolume_delete_recursive "$copydir" || + die "Unable to delete subvolume %s" "$copydir" + else + # avoid change of filesystem in case of an umount failure + rm --recursive --force --one-file-system "$copydir" || + die "Unable to delete %s" "$copydir" + fi + btrfs subvolume snapshot "$rootdir" "$copydir" >/dev/null || die "Unable to create subvolume %s" "$copydir" else mkdir -p "$copydir" - rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" + rsync -a --delete -q -W -x "$rootdir/" "$copydir" fi stat_done @@ -375,7 +381,7 @@ main() { lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" if [[ ! -d $copydir ]] || $clean_first; then - sync_chroot "$chrootdir" "$copydir" "$copy" + sync_chroot "$chrootdir/root" "$copydir" "$copy" fi $update_first && arch-nspawn "$copydir" \ |