]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Directly pass the context
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 12:52:45 +0000 (12:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 12:52:45 +0000 (12:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/lint.c
src/pakfire/archive.c
src/pakfire/archive.h
src/pakfire/package.c
src/pakfire/packager.c
src/pakfire/repo.c
src/python/archive.c
src/python/root.c
tests/libpakfire/archive.c
tests/libpakfire/db.c
tests/libpakfire/packager.c

index 63406a7252bd92a9d9b6cdce9dc61c027470e68a..0ddba1efd517705b02cd5e74c778456978b98265 100644 (file)
@@ -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;
        }
index 44458bc234df7926eb5e47dcf73e5f42a5571dde..c1a0703ba596beff6e4b92e5845686a4010e184a 100644 (file)
@@ -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);
index d78f985ea685346920641346958fe9a675150fe3..6806363f6ddb419468825c32b649bdbe63a114af 100644 (file)
@@ -27,6 +27,7 @@
 
 typedef struct pakfire_archive pakfire_archive;
 
+#include <pakfire/ctx.h>
 #include <pakfire/filelist.h>
 #include <pakfire/hashes.h>
 #include <pakfire/linter.h>
@@ -36,7 +37,9 @@ typedef struct pakfire_archive pakfire_archive;
 #include <pakfire/repo.h>
 #include <pakfire/scriptlet.h>
 
-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);
 
index 15da033bcbb9ad4e591391a779d11d6c68a95690..6e6a23b6f1002be86989a4e324c28deeda3bfd81 100644 (file)
@@ -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));
index c752a28ea376a02897697f1d1630179aea695b51..947b4ad2fd713781bc09c8d30887794c29ae8909 100644 (file)
@@ -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));
index 48281ea2978ae2f6fb8d287e01bc6b8f3b90ff55..ffb49e1498d7fe708cc86fb32fc9533449ca2a05 100644 (file)
@@ -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;
index 03069334ce07aead800371f1bbbe5344c2ce7b79..e47c8a477407a09e17c9a201c2e10d8b376506fa 100644 (file)
@@ -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;
index ffeb745afc9d039dcae6b4dc0c25bc59a4e317bb..666a1c59ac650e1883ff62b2b338dccf8e5a8d13 100644 (file)
@@ -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);
index 57dc5aaf7d641320e8b8f733d7d979220543d742..8a639567581ec48b8963eaece66a0421c6260bd8 100644 (file)
@@ -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
index e360178ac11cb9dd689f906c89b113b4fe1c2072..30db8410e754a52a42cb8db4752b01de623fccf2 100644 (file)
@@ -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
index 9917ca3c4b36f9ee0c66ae7e4f09a8b592eec656..6a8d348838a9c79212879b77b6cd6e8ca300e22f 100644 (file)
@@ -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));