]> git.ipfire.org Git - pakfire.git/commitdiff
db: Directly pass the context
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 13:04:18 +0000 (13:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 13:04:18 +0000 (13:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/db.c
src/pakfire/db.h
src/pakfire/root.c
src/pakfire/transaction.c
tests/libpakfire/db.c

index fb73e40058a0d2f9ac516ce94f5576480191f8a1..9b7a19d7e1c1cecf50c0cdc5af8eed6e1ba9d91a 100644 (file)
@@ -685,7 +685,7 @@ static int pakfire_db_setup(pakfire_db* db) {
        return 0;
 }
 
-int pakfire_db_open(pakfire_db** db, pakfire_root* root, int flags) {
+int pakfire_db_open(pakfire_db** db, pakfire_ctx* ctx, pakfire_root* root, int flags) {
        pakfire_db* self = NULL;
        int sqlite3_flags = 0;
        int r;
@@ -696,7 +696,7 @@ int pakfire_db_open(pakfire_db** db, pakfire_root* root, int flags) {
                return -errno;
 
        // Store a reference to the context
-       self->ctx = pakfire_root_get_ctx(root);
+       self->ctx = pakfire_ctx_ref(ctx);
 
        // Store a reference to the root
        self->root = pakfire_root_ref(root);
index 7bb3f249bf1274bd22e83da0a564fc574bbda3a1..548975894cc499bd948ea66eb732beb8630f622c 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 
 #include <pakfire/archive.h>
+#include <pakfire/ctx.h>
 #include <pakfire/package.h>
 #include <pakfire/root.h>
 #include <pakfire/repo.h>
@@ -36,7 +37,7 @@ enum {
        PAKFIRE_DB_READWRITE = (1 << 0),
 };
 
-int pakfire_db_open(pakfire_db** db, pakfire_root* root, int flags);
+int pakfire_db_open(pakfire_db** db, pakfire_ctx* ctx, pakfire_root* root, int flags);
 
 pakfire_db* pakfire_db_ref(pakfire_db* db);
 pakfire_db* pakfire_db_unref(pakfire_db* db);
index 00c61b38f481bfc17d94133cf64f6aefc10892ba..97703ee9b7ad6a04e8d23a46fdf9f7009fd19f24 100644 (file)
@@ -400,7 +400,7 @@ static int pakfire_root_load_installed_packages(pakfire_root* self) {
        repo = pakfire_root_get_repo(self, PAKFIRE_REPO_SYSTEM);
 
        // Open the database (or create a new one)
-       r = pakfire_db_open(&db, self, PAKFIRE_DB_READWRITE);
+       r = pakfire_db_open(&db, self->ctx, self, PAKFIRE_DB_READWRITE);
        if (r < 0)
                goto ERROR;
 
@@ -1883,7 +1883,7 @@ int pakfire_root_check(pakfire_root* self, pakfire_filelist* errors) {
        int r;
 
        // Open database in read-only mode and try to load all installed packages
-       r = pakfire_db_open(&db, self, PAKFIRE_DB_READWRITE);
+       r = pakfire_db_open(&db, self->ctx, self, PAKFIRE_DB_READWRITE);
        if (r)
                goto ERROR;
 
index e4a8a715d3649c7eb83beeb481be8218ce2b037b..71ace00d3845540d32baf5565a1bb4cfecf83188 100644 (file)
@@ -1868,7 +1868,7 @@ static int pakfire_transaction_perform(pakfire_transaction* transaction) {
                return r;
 
        // Open the database
-       r = pakfire_db_open(&db, transaction->root, PAKFIRE_DB_READWRITE);
+       r = pakfire_db_open(&db, transaction->ctx, transaction->root, PAKFIRE_DB_READWRITE);
        if (r) {
                ERROR(transaction->ctx, "Could not open the database\n");
                return r;
index 30db8410e754a52a42cb8db4752b01de623fccf2..5f3b335dd1697be6b3b1523414f881ba8fceae25 100644 (file)
@@ -30,7 +30,7 @@ static int test_open_ro(const struct test* t) {
        pakfire_db* db = NULL;
        int r = EXIT_FAILURE;
 
-       ASSERT_SUCCESS(pakfire_db_open(&db, t->root, PAKFIRE_DB_READONLY));
+       ASSERT_SUCCESS(pakfire_db_open(&db, t->ctx, t->root, PAKFIRE_DB_READONLY));
 
        // Everything passed
        r = EXIT_SUCCESS;
@@ -46,7 +46,7 @@ static int test_open_rw(const struct test* t) {
        pakfire_db* db = NULL;
        int r = EXIT_FAILURE;
 
-       ASSERT_SUCCESS(pakfire_db_open(&db, t->root, PAKFIRE_DB_READWRITE));
+       ASSERT_SUCCESS(pakfire_db_open(&db, t->ctx, t->root, PAKFIRE_DB_READWRITE));
 
        // Everything passed
        r = EXIT_SUCCESS;
@@ -62,7 +62,7 @@ static int test_check(const struct test* t) {
        pakfire_db* db = NULL;
        int r = EXIT_FAILURE;
 
-       ASSERT_SUCCESS(pakfire_db_open(&db, t->root, PAKFIRE_DB_READWRITE));
+       ASSERT_SUCCESS(pakfire_db_open(&db, t->ctx, t->root, PAKFIRE_DB_READWRITE));
 
        // Perform check
        ASSERT_SUCCESS(pakfire_db_check(db));
@@ -86,7 +86,7 @@ static int test_add_package(const struct test* t) {
 
        ASSERT(repo = pakfire_root_get_repo(t->root, PAKFIRE_REPO_DUMMY));
 
-       ASSERT_SUCCESS(pakfire_db_open(&db, t->root, PAKFIRE_DB_READWRITE));
+       ASSERT_SUCCESS(pakfire_db_open(&db, t->ctx, t->root, PAKFIRE_DB_READWRITE));
 
        // There must be no packages installed
        ssize_t packages = pakfire_db_packages(db);