From: Michael Tremer Date: Sun, 29 Jun 2025 13:47:45 +0000 (+0000) Subject: package: Directly pass the context X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=522b1f87cb59203222264e1744a94ee58b5836a3;p=pakfire.git package: Directly pass the context Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/archive.c b/src/pakfire/archive.c index 8ba1014b..7dc50875 100644 --- a/src/pakfire/archive.c +++ b/src/pakfire/archive.c @@ -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; diff --git a/src/pakfire/db.c b/src/pakfire/db.c index 35a777ea..fd22bf9a 100644 --- a/src/pakfire/db.c +++ b/src/pakfire/db.c @@ -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; diff --git a/src/pakfire/package.c b/src/pakfire/package.c index 225da9d7..93e4c587 100644 --- a/src/pakfire/package.c +++ b/src/pakfire/package.c @@ -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; } diff --git a/src/pakfire/package.h b/src/pakfire/package.h index 484b3c27..da4c4fef 100644 --- a/src/pakfire/package.h +++ b/src/pakfire/package.h @@ -32,6 +32,7 @@ typedef struct pakfire_package pakfire_package; +#include #include #include #include @@ -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); diff --git a/src/pakfire/packagelist.c b/src/pakfire/packagelist.c index 28b14eef..3ccadb6f 100644 --- a/src/pakfire/packagelist.c +++ b/src/pakfire/packagelist.c @@ -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; diff --git a/src/pakfire/parser.c b/src/pakfire/parser.c index 29a040fd..12664d1e 100644 --- a/src/pakfire/parser.c +++ b/src/pakfire/parser.c @@ -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; diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index ffb49e14..a310036b 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -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; diff --git a/src/pakfire/transaction.c b/src/pakfire/transaction.c index 5492b252..f6d7e319 100644 --- a/src/pakfire/transaction.c +++ b/src/pakfire/transaction.c @@ -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; diff --git a/src/python/package.c b/src/python/package.c index 9490cdfb..8fdf0b5f 100644 --- a/src/python/package.c +++ b/src/python/package.c @@ -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); diff --git a/tests/libpakfire/deps.c b/tests/libpakfire/deps.c index 878a2fa5..8a7c09dd 100644 --- a/tests/libpakfire/deps.c +++ b/tests/libpakfire/deps.c @@ -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 diff --git a/tests/libpakfire/package.c b/tests/libpakfire/package.c index 3b022971..2d5fc2e4 100644 --- a/tests/libpakfire/package.c +++ b/tests/libpakfire/package.c @@ -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 diff --git a/tests/libpakfire/packager.c b/tests/libpakfire/packager.c index 6a8d3488..6172fea1 100644 --- a/tests/libpakfire/packager.c +++ b/tests/libpakfire/packager.c @@ -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