]> git.ipfire.org Git - pakfire.git/commitdiff
snapshots: Tell the mount operation where to mount the snapshot
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Oct 2024 16:53:01 +0000 (16:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Oct 2024 16:53:01 +0000 (16:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/snapshot.h
src/libpakfire/pakfire.c
src/libpakfire/snapshot.c

index ce587f2cd4ddb3a014b393820697db8b64c25756..845db993089d65eef2368f84f681d5a1f15fdc05 100644 (file)
@@ -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
index 9f5e338b651ce4e1104e9e97f999715facb74887..fab65610dc4ce9b3481630ef62150e0d9b8ec4b2 100644 (file)
@@ -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);
                }
        }
 
index 6b13ed26ff71ff0f99110c2506f185c8f0bbf3cf..dcfdd614001fdb58133ef4d5402d6950c61f36bc 100644 (file)
@@ -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