From: Michael Tremer Date: Thu, 17 Oct 2024 16:53:01 +0000 (+0000) Subject: snapshots: Tell the mount operation where to mount the snapshot X-Git-Tag: 0.9.30~1035 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=59dfdf1ed00b67f2eb2e67c91a3cd260710dcb27;p=pakfire.git snapshots: Tell the mount operation where to mount the snapshot Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/snapshot.h b/src/libpakfire/include/pakfire/snapshot.h index ce587f2cd..845db9930 100644 --- a/src/libpakfire/include/pakfire/snapshot.h +++ b/src/libpakfire/include/pakfire/snapshot.h @@ -39,7 +39,7 @@ int pakfire_snapshot_find(struct pakfire_snapshot** snapshot, struct pakfire* pa const char* pakfire_snapshot_path(struct pakfire_snapshot* snapshot); -int pakfire_snapshot_mount(struct pakfire_snapshot* snapshot); +int pakfire_snapshot_mount(struct pakfire_snapshot* snapshot, const char* path); int pakfire_snapshot_umount(struct pakfire_snapshot* snapshot); #endif diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 9f5e338b6..fab65610d 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -847,14 +847,11 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* // Mount the snapshot if (p->snapshot) { - r = pakfire_snapshot_mount(p->snapshot); + r = pakfire_snapshot_mount(p->snapshot, path); if (r < 0) { CTX_ERROR(p->ctx, "Could not mount snapshot: %s\n", strerror(-r)); goto ERROR; } - - // Fetch the path where the snapshot was mounted - path = pakfire_snapshot_path(p->snapshot); } } diff --git a/src/libpakfire/snapshot.c b/src/libpakfire/snapshot.c index 6b13ed26f..dcfdd6140 100644 --- a/src/libpakfire/snapshot.c +++ b/src/libpakfire/snapshot.c @@ -209,10 +209,6 @@ ERROR: return r; } -const char* pakfire_snapshot_path(struct pakfire_snapshot* snapshot) { - return snapshot->overlayfs.path; -} - static int pakfire_snapshot_mount_tmpfs(struct pakfire_snapshot* snapshot) { char* path = NULL; int r; @@ -255,13 +251,12 @@ static int pakfire_snapshot_mount_tmpfs(struct pakfire_snapshot* snapshot) { return 0; } -int pakfire_snapshot_mount(struct pakfire_snapshot* snapshot) { - const char* path = NULL; +int pakfire_snapshot_mount(struct pakfire_snapshot* snapshot, const char* path) { int mountfd = -EBADF; int fsfd = -EBADF; int r; - CTX_DEBUG(snapshot->ctx, "Mounting snapshot %s\n", snapshot->path); + CTX_DEBUG(snapshot->ctx, "Mounting snapshot %s to %s\n", snapshot->path, path); // Mount the tmpfs r = pakfire_snapshot_mount_tmpfs(snapshot); @@ -302,16 +297,11 @@ int pakfire_snapshot_mount(struct pakfire_snapshot* snapshot) { goto ERROR; } - // Make path - r = pakfire_string_set(snapshot->overlayfs.path, PAKFIRE_TMP_DIR "/pakfire-root.XXXXXX"); + // Store the path + r = pakfire_string_set(snapshot->overlayfs.path, path); if (r < 0) goto ERROR; - // Create a temporary directory - path = pakfire_mkdtemp(snapshot->overlayfs.path); - if (!path) - goto ERROR; - // Move the snapshot to the right place r = move_mount(mountfd, "", AT_FDCWD, path, MOVE_MOUNT_F_EMPTY_PATH); if (r < 0) @@ -334,10 +324,6 @@ int pakfire_snapshot_umount(struct pakfire_snapshot* snapshot) { r = umount(snapshot->overlayfs.path); if (r < 0) return r; - - r = pakfire_rmtree(snapshot->overlayfs.path, 0); - if (r < 0) - return r; } // Umount the tmpfs