summaryrefslogtreecommitdiff
path: root/lib/archroot.sh
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2017-05-05 18:41:00 -0400
committerErich Eckner <git@eckner.net>2017-07-14 06:54:28 +0200
commite9e3fc8b50b1b492f0ee77bd503a729bfc2c98fe (patch)
treec92e5574dc7bf11a536a043011bb4e7f272c2c89 /lib/archroot.sh
parent89e08408ff3e28268a992c5279713c8cf44d7eef (diff)
downloaddevtools32-e9e3fc8b50b1b492f0ee77bd503a729bfc2c98fe.tar.xz
makechrootpkg: sync_chroot: Make more general.
This is inspired by the thought that went in to the delete_chroot is_subvolume commit. sync_chroot($chrootdir, $copydir) copies `$chrootdir/root` to `$copydir`. That seems a little silly; why do we care about "$chrootdir"? Have it just be sync_chroot(source, destination) like every other sync/copy command. Where this becomes tricky is check to decide if we are going to use btrfs subvolumes or not. We don't care if "$source/.." is on btrfs; the root could be a directly-mounted subvolume, but and the destination could be another subvolume of the same btrfs mounted somewhere else. The things we do care about are: - The source is a btrfs subvolume (so that we can snapshot it) - The source is on the same filesystem as the directory that the copy will be created in. - If the destination exists: * that it is not a mountpoint (so that we can delete and recreate it) * that it is a btrfs subvolume (so that we can quickly delete it) On the last point, it isn't necessary for creating the new snapshot, just for quick deletion. That can be a separate check, where we use regular `rm` for deleting the existing copy, but use subvolume snapshots for creating the new one.
Diffstat (limited to 'lib/archroot.sh')
-rw-r--r--lib/archroot.sh8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/archroot.sh b/lib/archroot.sh
index 87c28a2..6b1b52e 100644
--- a/lib/archroot.sh
+++ b/lib/archroot.sh
@@ -34,6 +34,14 @@ is_subvolume() {
}
##
+# usage : is_same_fs( $path_a, $path_b )
+# return : whether $path_a and $path_b are on the same filesystem
+##
+is_same_fs() {
+ [[ "$(stat -c %d "$1")" == "$(stat -c %d "$1")" ]]
+}
+
+##
# usage : subvolume_delete_recursive( $path )
#
# Find all btrfs subvolumes under and including $path and delete them.