From: Michael Tremer Date: Sun, 29 Jun 2025 12:52:45 +0000 (+0000) Subject: archive: Directly pass the context X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e78d3cdd9ba74fffec934f3a45970014f79f175c;p=pakfire.git archive: Directly pass the context Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/lint.c b/src/cli/lib/lint.c index 63406a72..0ddba1ef 100644 --- a/src/cli/lib/lint.c +++ b/src/cli/lib/lint.c @@ -85,12 +85,12 @@ static int cli_linter_result(pakfire_ctx* ctx, pakfire_archive* archive, return 0; } -static int do_lint(pakfire_root* root, const char* path) { +static int do_lint(pakfire_ctx* ctx, pakfire_root* root, const char* path) { pakfire_archive* archive = NULL; int r; // Open the archive - r = pakfire_archive_open(&archive, root, path); + r = pakfire_archive_open(&archive, ctx, root, path); if (r < 0) { fprintf(stderr, "Could not open %s: %s\n", path, strerror(-r)); goto ERROR; @@ -128,7 +128,7 @@ int cli_lint(void* data, int argc, char* argv[]) { // Lint all archives for (unsigned int i = 0; i < local_args.num_archives; i++) { - r = do_lint(root, local_args.archives[i]); + r = do_lint(global_args->ctx, root, local_args.archives[i]); if (r < 0) goto ERROR; } diff --git a/src/pakfire/archive.c b/src/pakfire/archive.c index 44458bc2..c1a0703b 100644 --- a/src/pakfire/archive.c +++ b/src/pakfire/archive.c @@ -694,7 +694,8 @@ static int pakfire_archive_read_metadata(pakfire_archive* archive) { return 0; } -int pakfire_archive_open(pakfire_archive** archive, pakfire_root* root, const char* path) { +int pakfire_archive_open(pakfire_archive** archive, + pakfire_ctx* ctx, pakfire_root* root, const char* path) { pakfire_archive* a = NULL; int r; @@ -704,7 +705,7 @@ int pakfire_archive_open(pakfire_archive** archive, pakfire_root* root, const ch return -errno; // Store a reference to the context - a->ctx = pakfire_root_get_ctx(root); + a->ctx = pakfire_ctx_ref(ctx); // Store a reference to pakfire a->root = pakfire_root_ref(root); diff --git a/src/pakfire/archive.h b/src/pakfire/archive.h index d78f985e..6806363f 100644 --- a/src/pakfire/archive.h +++ b/src/pakfire/archive.h @@ -27,6 +27,7 @@ typedef struct pakfire_archive pakfire_archive; +#include #include #include #include @@ -36,7 +37,9 @@ typedef struct pakfire_archive pakfire_archive; #include #include -int pakfire_archive_open(pakfire_archive** archive, pakfire_root* root, const char* path); +int pakfire_archive_open(pakfire_archive** archive, + pakfire_ctx* ctx, pakfire_root* root, const char* path); + pakfire_archive* pakfire_archive_ref(pakfire_archive* archive); pakfire_archive* pakfire_archive_unref(pakfire_archive* archive); diff --git a/src/pakfire/package.c b/src/pakfire/package.c index 15da033b..6e6a23b6 100644 --- a/src/pakfire/package.c +++ b/src/pakfire/package.c @@ -2255,7 +2255,7 @@ int pakfire_package_get_archive(pakfire_package* pkg, pakfire_archive** archive) return -errno; // Open archive - r = pakfire_archive_open(archive, pkg->root, path); + r = pakfire_archive_open(archive, pkg->ctx, pkg->root, path); if (r < 0) { ERROR(pkg->ctx, "Could not open archive for %s (at %s): %s\n", pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA), path, strerror(-r)); diff --git a/src/pakfire/packager.c b/src/pakfire/packager.c index c752a28e..947b4ad2 100644 --- a/src/pakfire/packager.c +++ b/src/pakfire/packager.c @@ -410,7 +410,7 @@ int pakfire_packager_write_archive(pakfire_packager* self, f = NULL; // Open the archive - r = pakfire_archive_open(archive, self->root, path); + r = pakfire_archive_open(archive, self->ctx, self->root, path); if (r < 0) { ERROR(self->ctx, "Could not open the generated archive at %s: %s\n", path, strerror(-r)); diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index 48281ea2..ffb49e14 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -682,7 +682,7 @@ static int __pakfire_repo_scan_archive(pakfire_repo* repo, } // Open archive - r = pakfire_archive_open(&archive, repo->root, entry->fts_path); + r = pakfire_archive_open(&archive, repo->ctx, repo->root, entry->fts_path); if (r < 0) goto ERROR; @@ -2007,7 +2007,7 @@ int pakfire_repo_add(pakfire_repo* repo, const char* path, } // Try to open the archive - r = pakfire_archive_open(&archive, repo->root, path); + r = pakfire_archive_open(&archive, repo->ctx, repo->root, path); if (r < 0) goto ERROR; @@ -2617,7 +2617,7 @@ int pakfire_repo_compose(pakfire_ctx* ctx, pakfire_root* root, DEBUG(ctx, "Adding %s to repository...\n", *file); // Open source archive - r = pakfire_archive_open(&archive, root, *file); + r = pakfire_archive_open(&archive, ctx, root, *file); if (r) { ERROR(ctx, "Could not open %s: %m\n", *file); goto OUT; diff --git a/src/python/archive.c b/src/python/archive.c index 03069334..e47c8a47 100644 --- a/src/python/archive.c +++ b/src/python/archive.c @@ -67,7 +67,7 @@ static int Archive_init(ArchiveObject* self, PyObject* args, PyObject* kwds) { if (!PyArg_ParseTuple(args, "O!s", &RootType, &root, &filename)) return -1; - errno = -pakfire_archive_open(&self->archive, root->root, filename); + errno = -pakfire_archive_open(&self->archive, root->ctx->ctx, root->root, filename); if (errno) { PyErr_SetFromErrno(PyExc_OSError); return -1; diff --git a/src/python/root.c b/src/python/root.c index ffeb745a..666a1c59 100644 --- a/src/python/root.c +++ b/src/python/root.c @@ -443,7 +443,7 @@ static PyObject* Root_open(RootObject* self, PyObject* args) { Py_BEGIN_ALLOW_THREADS - int r = pakfire_archive_open(&archive, self->root, path); + int r = pakfire_archive_open(&archive, self->ctx->ctx, self->root, path); if (r) { Py_BLOCK_THREADS PyErr_SetFromErrno(PyExc_OSError); diff --git a/tests/libpakfire/archive.c b/tests/libpakfire/archive.c index 57dc5aaf..8a639567 100644 --- a/tests/libpakfire/archive.c +++ b/tests/libpakfire/archive.c @@ -36,7 +36,7 @@ static int test_open(const struct test* t) { int r = EXIT_FAILURE; // Open the archive - ASSERT_SUCCESS(pakfire_archive_open(&archive, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->ctx, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); // Check if path was set correctly ASSERT_STRING_EQUALS(pakfire_archive_get_path(archive), TEST_SRC_PATH TEST_PKG1_PATH); @@ -73,7 +73,7 @@ static int test_open_directory(const struct test* t) { int r = EXIT_FAILURE; // Open the archive - ASSERT_ERROR(pakfire_archive_open(&archive, t->root, TEST_SRC_PATH), EISDIR); + ASSERT_ERROR(pakfire_archive_open(&archive, t->ctx, t->root, TEST_SRC_PATH), EISDIR); ASSERT_NULL(archive); // Everything passed @@ -99,7 +99,7 @@ static int test_read(const struct test* t) { }; // Open the archive - ASSERT_SUCCESS(pakfire_archive_open(&archive, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->ctx, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); // Read a file ASSERT(f = pakfire_archive_read(archive, "/usr/bin/beep", 0)); @@ -141,7 +141,7 @@ static int test_copy(const struct test* t) { ASSERT(f && path); // Open the archive - ASSERT_SUCCESS(pakfire_archive_open(&archive, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->ctx, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); // Copy archive ASSERT_SUCCESS(pakfire_archive_copy(archive, path)); @@ -168,7 +168,7 @@ static int test_filelist(const struct test* t) { int r = EXIT_FAILURE; // Open the archive - ASSERT_SUCCESS(pakfire_archive_open(&archive, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->ctx, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); // Fetch the filelist ASSERT_SUCCESS(pakfire_archive_get_filelist(archive, &list)); @@ -193,7 +193,7 @@ static int test_extract(const struct test* t) { char path[PATH_MAX]; int r = EXIT_FAILURE; - ASSERT_SUCCESS(pakfire_archive_open(&archive, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->ctx, t->root, TEST_SRC_PATH TEST_PKG1_PATH)); // Extract the archive payload ASSERT_SUCCESS(pakfire_archive_extract(archive, NULL, 0, NULL)); @@ -220,7 +220,7 @@ static int test_import(const struct test* t) { pakfire_package* package = NULL; // Open archive - ASSERT_SUCCESS(pakfire_archive_open(&archive, t->root, path)); + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->ctx, t->root, path)); ASSERT(archive); // Create a new repository diff --git a/tests/libpakfire/db.c b/tests/libpakfire/db.c index e360178a..30db8410 100644 --- a/tests/libpakfire/db.c +++ b/tests/libpakfire/db.c @@ -95,7 +95,7 @@ static int test_add_package(const struct test* t) { const char* path = TEST_SRC_PATH "/data/beep-1.3-2.ip3.x86_64.pfm"; // Open archive - ASSERT_SUCCESS(pakfire_archive_open(&archive, t->root, path)); + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->ctx, t->root, path)); ASSERT(archive); // Get package diff --git a/tests/libpakfire/packager.c b/tests/libpakfire/packager.c index 9917ca3c..6a8d3488 100644 --- a/tests/libpakfire/packager.c +++ b/tests/libpakfire/packager.c @@ -97,7 +97,7 @@ static int test_compare_metadata(const struct test* t) { printf("Archive written to %s\n", path); // Try to open the archive - ASSERT_SUCCESS(pakfire_archive_open(&archive, t->root, path)); + ASSERT_SUCCESS(pakfire_archive_open(&archive, t->ctx, t->root, path)); // Parse package from archive ASSERT_SUCCESS(pakfire_archive_make_package(archive, repo, &pkg2));