From: Michael Tremer Date: Sun, 29 Jun 2025 13:04:18 +0000 (+0000) Subject: db: Directly pass the context X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=448ab5677f4132175c0fdc48ead1c14e2be7796c;p=pakfire.git db: Directly pass the context Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/db.c b/src/pakfire/db.c index fb73e400..9b7a19d7 100644 --- a/src/pakfire/db.c +++ b/src/pakfire/db.c @@ -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); diff --git a/src/pakfire/db.h b/src/pakfire/db.h index 7bb3f249..54897589 100644 --- a/src/pakfire/db.h +++ b/src/pakfire/db.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/src/pakfire/root.c b/src/pakfire/root.c index 00c61b38..97703ee9 100644 --- a/src/pakfire/root.c +++ b/src/pakfire/root.c @@ -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; diff --git a/src/pakfire/transaction.c b/src/pakfire/transaction.c index e4a8a715..71ace00d 100644 --- a/src/pakfire/transaction.c +++ b/src/pakfire/transaction.c @@ -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; diff --git a/tests/libpakfire/db.c b/tests/libpakfire/db.c index 30db8410..5f3b335d 100644 --- a/tests/libpakfire/db.c +++ b/tests/libpakfire/db.c @@ -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);