From: Michael Tremer Date: Thu, 17 Oct 2024 17:44:51 +0000 (+0000) Subject: snapshots: Remove the overly complicated struct X-Git-Tag: 0.9.30~1029 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43bad1d464605ad434eb32836501056d98997448;p=pakfire.git snapshots: Remove the overly complicated struct Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/snapshot.c b/src/libpakfire/snapshot.c index ccab9fcc6..d18eb3dbf 100644 --- a/src/libpakfire/snapshot.c +++ b/src/libpakfire/snapshot.c @@ -32,11 +32,6 @@ #include #include -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; }