From 3b2874cdae6dadce4b921b7dbe275d181809df21 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 29 Jun 2025 14:19:56 +0000 Subject: [PATCH] snapshot: Directly pass the context Signed-off-by: Michael Tremer --- src/pakfire/root.c | 6 +++--- src/pakfire/snapshot.c | 24 ++++++------------------ src/pakfire/snapshot.h | 8 +++++--- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/pakfire/root.c b/src/pakfire/root.c index cf5b4556..fe3965b5 100644 --- a/src/pakfire/root.c +++ b/src/pakfire/root.c @@ -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; diff --git a/src/pakfire/snapshot.c b/src/pakfire/snapshot.c index e990ee64..300f5608 100644 --- a/src/pakfire/snapshot.c +++ b/src/pakfire/snapshot.c @@ -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); diff --git a/src/pakfire/snapshot.h b/src/pakfire/snapshot.h index a2c2c155..f5e5aeb3 100644 --- a/src/pakfire/snapshot.h +++ b/src/pakfire/snapshot.h @@ -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 */ -- 2.47.2