]> git.ipfire.org Git - pakfire.git/commitdiff
snapshots: Remove the overly complicated struct
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Oct 2024 17:44:51 +0000 (17:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Oct 2024 17:44:51 +0000 (17:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/snapshot.c

index ccab9fcc6f22850b9f9dd09e69960113ac9107a1..d18eb3dbf2fc3e78dd9b43f599de0c621e6b7d0e 100644 (file)
 #include <pakfire/string.h>
 #include <pakfire/util.h>
 
-struct pakfire_snapshot_fs {
-       char path[PATH_MAX];
-       int fd;
-};
-
 struct pakfire_snapshot {
        struct pakfire_ctx* ctx;
        int nrefs;
@@ -46,9 +41,10 @@ struct pakfire_snapshot {
        int fd;
 
        // File Systems
-       struct pakfire_snapshot_fs overlayfs;
-       struct pakfire_snapshot_fs tmpfs;
+       char overlayfs[PATH_MAX];
+       char tmpfs[PATH_MAX];
 
+       // Overlayfs Directories
        char upperdir[PATH_MAX];
        char workdir[PATH_MAX];
 
@@ -64,10 +60,6 @@ static void pakfire_snapshot_free(struct pakfire_snapshot* snapshot) {
        // Ensure this is umounted
        pakfire_snapshot_umount(snapshot);
 
-       if (snapshot->overlayfs.fd >= 0)
-               close(snapshot->overlayfs.fd);
-       if (snapshot->tmpfs.fd >= 0)
-               close(snapshot->tmpfs.fd);
        if (snapshot->fd >= 0)
                close(snapshot->fd);
 
@@ -104,9 +96,6 @@ int pakfire_snapshot_create(
                goto ERROR;
        }
 
-       // Initialize the file descriptors
-       s->overlayfs.fd = s->tmpfs.fd = -EBADF;
-
        // XXX Check and lock the snapshot
 
        // Return the snapshot
@@ -222,22 +211,22 @@ static int pakfire_snapshot_mount_tmpfs(struct pakfire_snapshot* snapshot) {
        int r;
 
        // Make path
-       r = pakfire_string_set(snapshot->tmpfs.path, PAKFIRE_TMP_DIR "/pakfire-tmpfs.XXXXXX");
+       r = pakfire_string_set(snapshot->tmpfs, PAKFIRE_TMP_DIR "/pakfire-tmpfs.XXXXXX");
        if (r < 0)
                return r;
 
        // Create a temporary directory
-       path = pakfire_mkdtemp(snapshot->tmpfs.path);
+       path = pakfire_mkdtemp(snapshot->tmpfs);
        if (!path)
                return -errno;
 
        // Perform mount
-       r = mount("pakfire_tmpfs", snapshot->tmpfs.path, "tmpfs", 0, NULL);
+       r = mount("pakfire_tmpfs", snapshot->tmpfs, "tmpfs", 0, NULL);
        if (r < 0)
                return -errno;
 
        // Make the upper directory
-       r = pakfire_path_append(snapshot->upperdir, snapshot->tmpfs.path, "upper");
+       r = pakfire_path_append(snapshot->upperdir, snapshot->tmpfs, "upper");
        if (r < 0)
                return r;
 
@@ -247,7 +236,7 @@ static int pakfire_snapshot_mount_tmpfs(struct pakfire_snapshot* snapshot) {
                return r;
 
        // Make the work directory
-       r = pakfire_path_append(snapshot->workdir, snapshot->tmpfs.path, "work");
+       r = pakfire_path_append(snapshot->workdir, snapshot->tmpfs, "work");
        if (r < 0)
                return r;
 
@@ -306,7 +295,7 @@ int pakfire_snapshot_mount(struct pakfire_snapshot* snapshot, const char* path)
        }
 
        // Store the path
-       r = pakfire_string_set(snapshot->overlayfs.path, path);
+       r = pakfire_string_set(snapshot->overlayfs, path);
        if (r < 0)
                goto ERROR;
 
@@ -333,19 +322,19 @@ int pakfire_snapshot_umount(struct pakfire_snapshot* snapshot) {
        switch (snapshot->state) {
                case PAKFIRE_SNAPSHOT_MOUNTED:
                        // Umount the overlayfs
-                       if (*snapshot->overlayfs.path) {
-                               r = umount(snapshot->overlayfs.path);
+                       if (*snapshot->overlayfs) {
+                               r = umount(snapshot->overlayfs);
                                if (r < 0)
                                        return r;
                        }
 
                        // Umount the tmpfs
-                       if (*snapshot->tmpfs.path) {
-                               r = umount(snapshot->tmpfs.path);
+                       if (*snapshot->tmpfs) {
+                               r = umount(snapshot->tmpfs);
                                if (r < 0)
                                        return r;
 
-                               r = pakfire_rmtree(snapshot->tmpfs.path, 0);
+                               r = pakfire_rmtree(snapshot->tmpfs, 0);
                                if (r < 0)
                                        return r;
                        }