]> git.ipfire.org Git - pakfire.git/commitdiff
package: Directly pass the context
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 13:47:45 +0000 (13:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 13:47:45 +0000 (13:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
12 files changed:
src/pakfire/archive.c
src/pakfire/db.c
src/pakfire/package.c
src/pakfire/package.h
src/pakfire/packagelist.c
src/pakfire/parser.c
src/pakfire/repo.c
src/pakfire/transaction.c
src/python/package.c
tests/libpakfire/deps.c
tests/libpakfire/package.c
tests/libpakfire/packager.c

index 8ba1014b2794ca45927c0f833c16e2eb5c5b7e43..7dc50875c8383a725ab55e6d7d0e777820717da8 100644 (file)
@@ -1598,7 +1598,7 @@ static int pakfire_archive_make_package_from_json(pakfire_archive* archive,
        const char* arch = pakfire_archive_metadata_get(archive, "arch", NULL);
 
        // Create a new package object
-       r = pakfire_package_create(&pkg, archive->root, repo, name, evr, arch);
+       r = pakfire_package_create(&pkg, archive->ctx, archive->root, repo, name, evr, arch);
        if (r)
                return r;
 
index 35a777ea138d0a7e132ca54929bbbef8533b7d72..fd22bf9a48eb6e1707ac1b2267a1a347054d8057 100644 (file)
@@ -1852,7 +1852,7 @@ static int pakfire_db_load_package(pakfire_db* db, pakfire_repo* repo, sqlite3_s
        }
 
        // Create package
-       r = pakfire_package_create(&pkg, db->root, repo, name, evr, arch);
+       r = pakfire_package_create(&pkg, db->ctx, db->root, repo, name, evr, arch);
        if (r) {
                ERROR(db->ctx, "Could not create package '%s-%s.%s': %m\n", name, evr, arch);
                goto ERROR;
index 225da9d7e414d86f9d7ec2f4feb44dba9b136535..93e4c587914b23bd0b2c0d4374725091ef3dbaef 100644 (file)
@@ -168,7 +168,7 @@ static int pakfire_package_add_self_provides(pakfire_package* pkg) {
 }
 
 int pakfire_package_create_from_solvable(pakfire_package** package,
-               pakfire_root* root, pakfire_repo* repo, Id id) {
+               pakfire_ctx* ctx, pakfire_root* root, pakfire_repo* repo, Id id) {
        pakfire_package* pkg = NULL;
 
        // Allocate some memory
@@ -177,7 +177,7 @@ int pakfire_package_create_from_solvable(pakfire_package** package,
                return -errno;
 
        // Store a reference to the context
-       pkg->ctx = pakfire_root_get_ctx(root);
+       pkg->ctx = pakfire_ctx_ref(ctx);
 
        // Store a reference to the root
        pkg->root = pakfire_root_ref(root);
@@ -198,7 +198,7 @@ int pakfire_package_create_from_solvable(pakfire_package** package,
        return 0;
 }
 
-int pakfire_package_create(pakfire_package** package, pakfire_root* root,
+int pakfire_package_create(pakfire_package** package, pakfire_ctx* ctx, pakfire_root* root,
                pakfire_repo* repo, const char* name, const char* evr, const char* arch) {
        pakfire_repo* dummy = NULL;
        int r;
@@ -220,9 +220,6 @@ int pakfire_package_create(pakfire_package** package, pakfire_root* root,
                repo = dummy;
        }
 
-       // Fetch the context
-       pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
        // Allocate a new solvable
        Id id = pakfire_repo_add_solvable(repo);
        if (!id) {
@@ -232,7 +229,7 @@ int pakfire_package_create(pakfire_package** package, pakfire_root* root,
        }
 
        // Create a new package object
-       r = pakfire_package_create_from_solvable(package, root, repo, id);
+       r = pakfire_package_create_from_solvable(package, ctx, root, repo, id);
        if (r)
                goto ERROR;
 
@@ -267,8 +264,6 @@ int pakfire_package_create(pakfire_package** package, pakfire_root* root,
 ERROR:
        if (dummy)
                pakfire_repo_unref(dummy);
-       if (ctx)
-               pakfire_ctx_unref(ctx);
 
        return r;
 }
index 484b3c27d2f188d207469051060c015ad637d8e6..da4c4fef7e99aaedcf9b8b7a40c89bd0097a46de 100644 (file)
@@ -32,6 +32,7 @@
 
 typedef struct pakfire_package pakfire_package;
 
+#include <pakfire/ctx.h>
 #include <pakfire/filelist.h>
 #include <pakfire/hashes.h>
 #include <pakfire/packagelist.h>
@@ -80,7 +81,7 @@ enum pakfire_package_key {
        PAKFIRE_PKG_ENHANCES,
 };
 
-int pakfire_package_create(pakfire_package** package, pakfire_root* root,
+int pakfire_package_create(pakfire_package** package, pakfire_ctx* ctx, pakfire_root* root,
        pakfire_repo* repo, const char* name, const char* evr, const char* arch);
 
 pakfire_package* pakfire_package_ref(pakfire_package* pkg);
@@ -158,7 +159,7 @@ enum pakfire_package_dump_flags {
 int pakfire_package_installcheck(pakfire_package* pkg, char** problem, int flags);
 
 int pakfire_package_create_from_solvable(pakfire_package** package,
-       pakfire_root* root, pakfire_repo* repo, Id id);
+       pakfire_ctx* ctx, pakfire_root* root, pakfire_repo* repo, Id id);
 
 int pakfire_package_set_strings_from_string(pakfire_package* pkg,
        const enum pakfire_package_key key, const char* value);
index 28b14eeffb79a7408a4b575470040cb755d5c89e..3ccadb6f3fe50c21eef49fb9a49702004ba41a5c 100644 (file)
@@ -209,7 +209,7 @@ int pakfire_packagelist_import_solvables(pakfire_packagelist* self,
 
        // Walk through all elements on the queue
        for (int i = 0; i < q->count; i++) {
-               r = pakfire_package_create_from_solvable(&pkg, root, NULL, q->elements[i]);
+               r = pakfire_package_create_from_solvable(&pkg, self->ctx, root, NULL, q->elements[i]);
                if (r)
                        return r;
 
index 29a040fd1865e994415e6f90a425314d9372973c..12664d1eed7243c9b431ce6f7dd8aaf1d34f54d2 100644 (file)
@@ -1073,7 +1073,8 @@ int pakfire_parser_create_package(pakfire_parser* parser,
        }
 
        // Create a new package object
-       r = pakfire_package_create(pkg, parser->root, repo, name, evr, (arch) ? arch : default_arch);
+       r = pakfire_package_create(pkg, parser->ctx, parser->root,
+                       repo, name, evr, (arch) ? arch : default_arch);
        if (r < 0) {
                ERROR(parser->ctx, "Could not create package: %m\n");
                goto CLEANUP;
index ffb49e1498d7fe708cc86fb32fc9533449ca2a05..a310036bd169da27aa0e8c02d48cb042df79ec11 100644 (file)
@@ -463,7 +463,7 @@ static int pakfire_repo_to_packagelist(
                id = pool_solvable2id(self->repo->pool, s);
 
                // Create a new package
-               r = pakfire_package_create_from_solvable(&pkg, self->root, self, id);
+               r = pakfire_package_create_from_solvable(&pkg, self->ctx, self->root, self, id);
                if (r < 0)
                        goto ERROR;
 
@@ -2128,7 +2128,7 @@ static int pakfire_repo_delete_all_packages(
                Id id = pool_solvable2id(pool, s);
 
                // Allocate package
-               r = pakfire_package_create_from_solvable(&pkg, repo->root, repo, id);
+               r = pakfire_package_create_from_solvable(&pkg, repo->ctx, repo->root, repo, id);
                if (r)
                        return 1;
 
index 5492b25299831fc631da3f7efd1558ee403461c8..f6d7e3198842f44288a2fcb720786372b7637df4 100644 (file)
@@ -207,7 +207,7 @@ static int pakfire_transaction_import_transaction(pakfire_transaction* transacti
 
        // Create all packages
        for (unsigned int i = 0; i < transaction->num; i++) {
-               r = pakfire_package_create_from_solvable(&transaction->packages[i],
+               r = pakfire_package_create_from_solvable(&transaction->packages[i], transaction->ctx,
                        transaction->root, NULL, transaction->transaction->steps.elements[i]);
                if (r < 0)
                        goto ERROR;
@@ -218,7 +218,7 @@ static int pakfire_transaction_import_transaction(pakfire_transaction* transacti
 
        // Store all newly installed and overall all installed packages
        for (int i = 0; i < pkgs.count; i++) {
-               r = pakfire_package_create_from_solvable(&pkg,
+               r = pakfire_package_create_from_solvable(&pkg, transaction->ctx,
                                transaction->root, NULL, pkgs.elements[i]);
                if (r < 0)
                        goto ERROR;
@@ -1160,16 +1160,16 @@ char* pakfire_transaction_dump(pakfire_transaction* transaction, size_t width) {
                        pakfire_package* old_pkg = NULL;
                        pakfire_package* new_pkg = NULL;
 
-                       r = pakfire_package_create_from_solvable(&old_pkg, transaction->root,
-                                       NULL, pkgs.elements[j]);
+                       r = pakfire_package_create_from_solvable(&old_pkg, transaction->ctx,
+                                       transaction->root, NULL, pkgs.elements[j]);
                        if (r)
                                continue;
 
                        switch (class) {
                                case SOLVER_TRANSACTION_UPGRADED:
                                case SOLVER_TRANSACTION_DOWNGRADED:
-                                       r = pakfire_package_create_from_solvable(&new_pkg, transaction->root,
-                                                       NULL, transaction_obs_pkg(transaction->transaction, pkgs.elements[j]));
+                                       r = pakfire_package_create_from_solvable(&new_pkg, transaction->ctx,
+                                                       transaction->root, NULL, transaction_obs_pkg(transaction->transaction, pkgs.elements[j]));
                                        if (r)
                                                continue;
 
index 9490cdfbe01bea5e247d950715592c76df159ac8..8fdf0b5f3f01d0ede283e6c7fd11fbafc1ee53e7 100644 (file)
@@ -73,7 +73,8 @@ static int Package_init(PackageObject* self, PyObject* args, PyObject* kwds) {
                return -1;
 
        // Create the package object
-       r = pakfire_package_create(&self->package, root->root, repo->repo, name, evr, arch);
+       r = pakfire_package_create(&self->package, root->ctx->ctx, root->root,
+                       repo->repo, name, evr, arch);
        if (r < 0) {
                errno = -r;
                PyErr_SetFromErrno(PyExc_OSError);
index 878a2fa575df4251f082ea4510c4cca8d6340118..8a7c09dd92c486f26a4a472398459c0e6b051ea0 100644 (file)
@@ -177,7 +177,7 @@ static int test_dep_match(const struct test* t) {
        pakfire_package* pkg = NULL;
        int r = EXIT_FAILURE;
 
-       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->root, NULL,
+       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
                "test", "1.0-1", "x86_64"));
 
        // Check if the package matches itself
index 3b022971b626fd712a20bb053a0e28431caf26ff..2d5fc2e4fbd4460e159aaf84db698dba7a3a9f63 100644 (file)
@@ -36,7 +36,8 @@ static int test_create(const struct test* t) {
        char** groups = NULL;
        int r = EXIT_FAILURE;
 
-       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->root, NULL, "test", "1.0-1", "x86_64"));
+       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
+               "test", "1.0-1", "x86_64"));
 
        ASSERT_STRING_EQUALS(pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME), "test");
        ASSERT_STRING_EQUALS(pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR), "1.0-1");
@@ -155,12 +156,16 @@ static int test_invalid_inputs(const struct test* t) {
        int r = EXIT_FAILURE;
 
        // Try to create a package with some values missing
-       ASSERT_ERRNO(pakfire_package_create(&pkg, t->root, NULL, NULL, "1.0-1", "src"), EINVAL);
-       ASSERT_ERRNO(pakfire_package_create(&pkg, t->root, NULL, "test", NULL, "src"), EINVAL);
-       ASSERT_ERRNO(pakfire_package_create(&pkg, t->root, NULL, "test", "1.0-1", NULL), EINVAL);
+       ASSERT_ERRNO(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
+               NULL, "1.0-1", "src"), EINVAL);
+       ASSERT_ERRNO(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
+               "test", NULL, "src"), EINVAL);
+       ASSERT_ERRNO(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
+               "test", "1.0-1", NULL), EINVAL);
 
        // Finally create a package
-       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->root, NULL, "test", "1.0-1", "x86_64"));
+       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
+               "test", "1.0-1", "x86_64"));
 
        // Try to set non-sense for strings
        ASSERT_ERRNO(pakfire_package_set_string(pkg, PAKFIRE_PKG_INSTALLTIME, "today"), EINVAL);
@@ -192,7 +197,8 @@ static int test_uuid(const struct test* t) {
        uuid_unparse(uuid, uuid_string);
 
        // Create a new package
-       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->root, NULL, "test", "1.0-1", "src"));
+       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
+               "test", "1.0-1", "src"));
 
        // Set the UUID
        ASSERT_SUCCESS(pakfire_package_set_uuid(pkg, PAKFIRE_PKG_UUID, uuid));
@@ -224,7 +230,8 @@ static int test_deps(const struct test* t) {
        char** deps = NULL;
        int r = EXIT_FAILURE;
 
-       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->root, NULL, "test", "1.0-1", "src"));
+       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
+               "test", "1.0-1", "src"));
 
        // Add a "provides"
        ASSERT_SUCCESS(pakfire_package_add_dep(pkg, PAKFIRE_PKG_PROVIDES, "a"));
@@ -271,7 +278,7 @@ static int test_filelist(const struct test* t) {
        ASSERT_EQUALS(pakfire_filelist_length(filelist), 1);
 
        // Create a new package
-       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->root, NULL,
+       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->ctx, t->root, NULL,
                "bash", "1.0-1", "i386"));
 
        // Set filelist
index 6a8d348838a9c79212879b77b6cd6e8ca300e22f..6172fea1c27f41d9af48ea181c6d8c5823ec8041 100644 (file)
@@ -36,7 +36,8 @@ static int test_create(const struct test* t) {
        ASSERT_SUCCESS(pakfire_repo_create(&repo, t->root, "test"));
        ASSERT(repo);
 
-       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->root, repo, "test", "1.0-1", "src"));
+       ASSERT_SUCCESS(pakfire_package_create(&pkg, t->ctx, t->root, repo,
+                       "test", "1.0-1", "src"));
 
        // Create packager
        ASSERT_SUCCESS(pakfire_packager_create(&packager, t->root, pkg));
@@ -77,7 +78,7 @@ static int test_compare_metadata(const struct test* t) {
        pakfire_repo* repo = pakfire_root_get_repo(t->root, PAKFIRE_REPO_DUMMY);
        ASSERT(repo);
 
-       ASSERT_SUCCESS(pakfire_package_create(&pkg1, t->root, repo,
+       ASSERT_SUCCESS(pakfire_package_create(&pkg1, t->ctx, t->root, repo,
                "test", "1.0-1", "x86_64"));
 
        // Set all metadata