]> git.ipfire.org Git - pakfire.git/commitdiff
snapshot: Directly pass the context
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 14:19:56 +0000 (14:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 14:19:56 +0000 (14:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/root.c
src/pakfire/snapshot.c
src/pakfire/snapshot.h

index cf5b4556ced5e5e9fc5f05e8d19212670d43ef1e..fe3965b55d5a346bc008b7f4b3d835cac5a0ee19 100644 (file)
@@ -1081,7 +1081,7 @@ int pakfire_root_create(pakfire_root** root, pakfire_ctx* ctx,
        // Are we using a snapshot?
        if (self->flags & PAKFIRE_ROOT_USE_SNAPSHOT) {
                // Find the most recent snapshot
-               r = pakfire_snapshot_find(&self->snapshot, self);
+               r = pakfire_snapshot_find(&self->snapshot, self->ctx, self);
                if (r < 0) {
                        ERROR(self->ctx, "Could not find a snapshot: %s\n", strerror(-r));
                        goto ERROR;
@@ -1303,7 +1303,7 @@ int pakfire_root_clean(pakfire_root* self, int flags) {
                return r;
 
        // Clean all snapshots
-       r = pakfire_snapshot_clean(self);
+       r = pakfire_snapshot_clean(self->ctx, self);
        if (r < 0)
                return r;
 
@@ -1914,7 +1914,7 @@ int pakfire_root_update_snapshot(pakfire_root* self) {
        int r;
 
        // Make a new snapshot
-       r = pakfire_snapshot_make(&snapshot, self);
+       r = pakfire_snapshot_make(&snapshot, self->ctx, self);
        if (r < 0)
                goto ERROR;
 
index e990ee641a4c362cdac12e91ef03b39ce407b8c8..300f5608daf8d1d689a6914a7ac1453cb9a261d1 100644 (file)
@@ -199,15 +199,13 @@ static int pakfire_snapshot_filter(const struct dirent* dirent) {
 /*
        Finds and returns the latest snapshot
 */
-int pakfire_snapshot_find(pakfire_snapshot** snapshot, pakfire_root* root) {
+int pakfire_snapshot_find(pakfire_snapshot** snapshot, pakfire_ctx* ctx, pakfire_root* root) {
        struct dirent** paths = NULL;
        int num_paths = 0;
        char path[PATH_MAX];
        int fd = -EBADF;
        int r;
 
-       pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
        // Make the path
        r = pakfire_root_cache_path(root, path, "%s", "snapshots");
        if (r < 0)
@@ -219,7 +217,7 @@ int pakfire_snapshot_find(pakfire_snapshot** snapshot, pakfire_root* root) {
                switch (errno) {
                        // If the directory does not exist, we will make a new snapshot
                        case ENOENT:
-                               r = pakfire_snapshot_make(snapshot, root);
+                               r = pakfire_snapshot_make(snapshot, ctx, root);
                                if (r < 0)
                                        goto ERROR;
 
@@ -240,7 +238,7 @@ int pakfire_snapshot_find(pakfire_snapshot** snapshot, pakfire_root* root) {
 
        // Create a new snapshot if none was found
        } else if (num_paths == 0) {
-               r = pakfire_snapshot_make(snapshot, root);
+               r = pakfire_snapshot_make(snapshot, ctx, root);
                if (r < 0)
                        goto ERROR;
 
@@ -273,8 +271,6 @@ ERROR:
        }
        if (fd >= 0)
                close(fd);
-       if (ctx)
-               pakfire_ctx_unref(ctx);
 
        return r;
 }
@@ -507,7 +503,7 @@ ERROR:
 /*
        Creates a new snapshot
 */
-int pakfire_snapshot_make(pakfire_snapshot** snapshot, pakfire_root* root) {
+int pakfire_snapshot_make(pakfire_snapshot** snapshot, pakfire_ctx* ctx, pakfire_root* root) {
        pakfire_config* config = NULL;
        pakfire_root* p = NULL;
        char snapshot_path[PATH_MAX];
@@ -523,8 +519,6 @@ int pakfire_snapshot_make(pakfire_snapshot** snapshot, pakfire_root* root) {
                NULL,
        };
 
-       pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
        // Fetch the configuration
        config = pakfire_root_get_config(root);
 
@@ -583,13 +577,11 @@ int pakfire_snapshot_make(pakfire_snapshot** snapshot, pakfire_root* root) {
                goto ERROR;
 
        // Cleanup any older snapshots (and ignore if something goes wrong)
-       pakfire_snapshot_clean(root);
+       pakfire_snapshot_clean(ctx, root);
 
 ERROR:
        if (config)
                pakfire_config_unref(config);
-       if (ctx)
-               pakfire_ctx_unref(ctx);
        if (p)
                pakfire_root_unref(p);
 
@@ -603,14 +595,12 @@ ERROR:
 /*
        Cleans up any unused snapshots
 */
-int pakfire_snapshot_clean(pakfire_root* root) {
+int pakfire_snapshot_clean(pakfire_ctx* ctx, pakfire_root* root) {
        pakfire_snapshot* snapshot = NULL;
        char path[PATH_MAX];
        FTS* f = NULL;
        int r;
 
-       pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
        DEBUG(ctx, "Cleaning up snapshots...\n");
 
        // Make the path
@@ -675,8 +665,6 @@ int pakfire_snapshot_clean(pakfire_root* root) {
 ERROR:
        if (snapshot)
                pakfire_snapshot_unref(snapshot);
-       if (ctx)
-               pakfire_ctx_unref(ctx);
        if (f)
                fts_close(f);
 
index a2c2c155ad93e8bf03073b8461d80d6886cd3510..f5e5aeb34a1772cf82d2b97e56da8110578237e8 100644 (file)
@@ -32,15 +32,17 @@ int pakfire_snapshot_create(
 pakfire_snapshot* pakfire_snapshot_ref(pakfire_snapshot* self);
 pakfire_snapshot* pakfire_snapshot_unref(pakfire_snapshot* self);
 
-int pakfire_snapshot_find(pakfire_snapshot** snapshot, pakfire_root* root);
+int pakfire_snapshot_find(pakfire_snapshot** snapshot,
+       pakfire_ctx* ctx, pakfire_root* root);
 
 const char* pakfire_snapshot_path(pakfire_snapshot* self);
 
 int pakfire_snapshot_mount(pakfire_snapshot* self, const char* path);
 int pakfire_snapshot_umount(pakfire_snapshot* self);
 
-int pakfire_snapshot_make(pakfire_snapshot** snapshot, pakfire_root* root);
+int pakfire_snapshot_make(pakfire_snapshot** snapshot,
+       pakfire_ctx* ctx, pakfire_root* root);
 
-int pakfire_snapshot_clean(pakfire_root* root);
+int pakfire_snapshot_clean(pakfire_ctx* ctx, pakfire_root* root);
 
 #endif /* PAKFIRE_SNAPSHOT_H */