From 449035ed7292955fa1e8bed781b9ca079179f3bb Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 29 Jun 2025 13:18:09 +0000 Subject: [PATCH] file: Directly pass the context Signed-off-by: Michael Tremer --- src/pakfire/archive.c | 4 ++-- src/pakfire/db.c | 2 +- src/pakfire/file.c | 11 ++++++----- src/pakfire/file.h | 6 ++++-- src/pakfire/filelist.c | 2 +- src/pakfire/linter.c | 2 +- src/pakfire/package.c | 4 +++- src/pakfire/packager.c | 2 +- src/pakfire/stripper.c | 2 +- tests/libpakfire/file.c | 10 +++++----- tests/libpakfire/package.c | 2 +- 11 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/pakfire/archive.c b/src/pakfire/archive.c index c1a0703b..631ffeab 100644 --- a/src/pakfire/archive.c +++ b/src/pakfire/archive.c @@ -1210,7 +1210,7 @@ static int pakfire_archive_extract_one(pakfire_archive* archive, } // Generate a file object - r = pakfire_file_create_from_archive_entry(&file, archive->root, entry); + r = pakfire_file_create_from_archive_entry(&file, archive->ctx, archive->root, entry); if (r < 0) goto ERROR; @@ -1446,7 +1446,7 @@ static int __pakfire_archive_load_filelist(pakfire_archive* archive, int r; // Generate a file object - r = pakfire_file_create_from_archive_entry(&file, archive->root, entry); + r = pakfire_file_create_from_archive_entry(&file, archive->ctx, archive->root, entry); if (r < 0) goto ERROR; diff --git a/src/pakfire/db.c b/src/pakfire/db.c index 9b7a19d7..f617b38b 100644 --- a/src/pakfire/db.c +++ b/src/pakfire/db.c @@ -2231,7 +2231,7 @@ static int pakfire_db_load_file(pakfire_db* db, pakfire_filelist* filelist, } // Create a new file object - r = pakfire_file_create(&file, db->root, path); + r = pakfire_file_create(&file, db->ctx, db->root, path); if (r < 0) goto ERROR; diff --git a/src/pakfire/file.c b/src/pakfire/file.c index 61f585e6..8dbee5c9 100644 --- a/src/pakfire/file.c +++ b/src/pakfire/file.c @@ -377,7 +377,8 @@ ERROR: return r; } -int pakfire_file_create(pakfire_file** file, pakfire_root* root, const char* path) { +int pakfire_file_create(pakfire_file** file, + pakfire_ctx* ctx, pakfire_root* root, const char* path) { pakfire_file* f = NULL; int r = 0; @@ -387,7 +388,7 @@ int pakfire_file_create(pakfire_file** file, pakfire_root* root, const char* pat return -errno; // Store a reference to the context - f->ctx = pakfire_root_get_ctx(root); + f->ctx = pakfire_ctx_ref(ctx); // Store reference to the root f->root = pakfire_root_ref(root); @@ -452,12 +453,12 @@ ERROR: return r; } -int pakfire_file_create_from_archive_entry(pakfire_file** file, pakfire_root* root, - struct archive_entry* entry) { +int pakfire_file_create_from_archive_entry(pakfire_file** file, + pakfire_ctx* ctx, pakfire_root* root, struct archive_entry* entry) { pakfire_file* f = NULL; int r; - r = pakfire_file_create(&f, root, NULL); + r = pakfire_file_create(&f, ctx, root, NULL); if (r < 0) goto ERROR; diff --git a/src/pakfire/file.h b/src/pakfire/file.h index 6b86ac0e..14afe9b4 100644 --- a/src/pakfire/file.h +++ b/src/pakfire/file.h @@ -32,6 +32,7 @@ typedef struct pakfire_file pakfire_file; +#include #include #include @@ -39,7 +40,8 @@ enum pakfire_file_flags { PAKFIRE_FILE_CONFIG = (1 << 0), }; -int pakfire_file_create(pakfire_file** file, pakfire_root* root, const char* path); +int pakfire_file_create(pakfire_file** file, + pakfire_ctx* ctx, pakfire_root* root, const char* path); pakfire_file* pakfire_file_ref(pakfire_file* file); pakfire_file* pakfire_file_unref(pakfire_file* file); @@ -133,7 +135,7 @@ int pakfire_file_has_payload(pakfire_file* file); int pakfire_file_write_fcaps(pakfire_file* file, struct vfs_cap_data* cap_data); int pakfire_file_create_from_archive_entry(pakfire_file** file, - pakfire_root* root, struct archive_entry* entry); + pakfire_ctx* ctx, pakfire_root* root, struct archive_entry* entry); struct archive_entry* pakfire_file_archive_entry(pakfire_file* file, const enum pakfire_hash_type hashes); enum pakfire_file_dump_flags { diff --git a/src/pakfire/filelist.c b/src/pakfire/filelist.c index c91718fd..4c0040f6 100644 --- a/src/pakfire/filelist.c +++ b/src/pakfire/filelist.c @@ -410,7 +410,7 @@ int pakfire_filelist_scan(pakfire_filelist* list, const char* root, } // Create file - r = pakfire_file_create_from_archive_entry(&file, list->root, entry); + r = pakfire_file_create_from_archive_entry(&file, list->ctx, list->root, entry); if (r) goto ERROR; diff --git a/src/pakfire/linter.c b/src/pakfire/linter.c index d44ac1be..3088c596 100644 --- a/src/pakfire/linter.c +++ b/src/pakfire/linter.c @@ -485,7 +485,7 @@ static int pakfire_linter_lint_file(pakfire_archive* archive, int r; // Fetch a file object - r = pakfire_file_create_from_archive_entry(&file, linter->root, e); + r = pakfire_file_create_from_archive_entry(&file, linter->ctx, linter->root, e); if (r < 0) goto ERROR; diff --git a/src/pakfire/package.c b/src/pakfire/package.c index 6e6a23b6..5f4248fa 100644 --- a/src/pakfire/package.c +++ b/src/pakfire/package.c @@ -2266,6 +2266,7 @@ int pakfire_package_get_archive(pakfire_package* pkg, pakfire_archive** archive) } typedef struct pakfire_package_filelist_search { + pakfire_ctx* ctx; pakfire_root* root; pakfire_filelist* filelist; int r; @@ -2290,7 +2291,7 @@ static int __pakfire_package_fetch_filelist(void* data, Solvable* s, Repodata* r } // Create a new file entry - r = pakfire_file_create(&file, search->root, path); + r = pakfire_file_create(&file, search->ctx, search->root, path); if (r < 0) goto ERROR; @@ -2311,6 +2312,7 @@ ERROR: static int pakfire_package_fetch_filelist(pakfire_package* pkg, pakfire_filelist* filelist) { pakfire_package_filelist_search search = { + .ctx = pkg->ctx, .root = pkg->root, .filelist = filelist, .r = 0, diff --git a/src/pakfire/packager.c b/src/pakfire/packager.c index 4e55e8d1..d6afd2fc 100644 --- a/src/pakfire/packager.c +++ b/src/pakfire/packager.c @@ -518,7 +518,7 @@ int pakfire_packager_add(pakfire_packager* packager, } // Create a new file object from the archive entry - r = pakfire_file_create_from_archive_entry(&file, packager->root, entry); + r = pakfire_file_create_from_archive_entry(&file, packager->ctx, packager->root, entry); if (r < 0) { ERROR(packager->ctx, "Could not create file object: %s\n", strerror(-r)); goto ERROR; diff --git a/src/pakfire/stripper.c b/src/pakfire/stripper.c index 8a1c2eea..cc89096b 100644 --- a/src/pakfire/stripper.c +++ b/src/pakfire/stripper.c @@ -224,7 +224,7 @@ static int pakfire_stripper_collect_sources( return 0; // Create a new file object - r = pakfire_file_create(&file, self->root, filename); + r = pakfire_file_create(&file, self->ctx, self->root, filename); if (r < 0) goto ERROR; diff --git a/tests/libpakfire/file.c b/tests/libpakfire/file.c index 8fae33f8..4a0a8f98 100644 --- a/tests/libpakfire/file.c +++ b/tests/libpakfire/file.c @@ -27,7 +27,7 @@ static int test_create(const struct test* t) { pakfire_file* file = NULL; // Create a new file - ASSERT_SUCCESS(pakfire_file_create(&file, t->root, NULL)); + ASSERT_SUCCESS(pakfire_file_create(&file, t->ctx, t->root, NULL)); // Set path & check ASSERT_SUCCESS(pakfire_file_set_path(file, "/abc")); @@ -46,7 +46,7 @@ static int test_create_invalid(const struct test* t) { pakfire_file* file = NULL; // Create a new file - ASSERT_SUCCESS(pakfire_file_create(&file, t->root, NULL)); + ASSERT_SUCCESS(pakfire_file_create(&file, t->ctx, t->root, NULL)); // Set path ASSERT(pakfire_file_set_path(file, NULL) == -EINVAL); @@ -71,9 +71,9 @@ static int test_create_filelist(const struct test* t) { ASSERT_SUCCESS(pakfire_filelist_create(&list, t->root)); // Create some files - ASSERT_SUCCESS(pakfire_file_create(&file1, t->root, "/1")); - ASSERT_SUCCESS(pakfire_file_create(&file2, t->root, "/2")); - ASSERT_SUCCESS(pakfire_file_create(&file3, t->root, "/3")); + ASSERT_SUCCESS(pakfire_file_create(&file1, t->ctx, t->root, "/1")); + ASSERT_SUCCESS(pakfire_file_create(&file2, t->ctx, t->root, "/2")); + ASSERT_SUCCESS(pakfire_file_create(&file3, t->ctx, t->root, "/3")); // Add the files to the list ASSERT_SUCCESS(pakfire_filelist_add(list, file1)); diff --git a/tests/libpakfire/package.c b/tests/libpakfire/package.c index 7f403308..71a73412 100644 --- a/tests/libpakfire/package.c +++ b/tests/libpakfire/package.c @@ -259,7 +259,7 @@ static int test_filelist(const struct test* t) { ASSERT_SUCCESS(pakfire_filelist_create(&filelist, t->root)); // Create a file - ASSERT_SUCCESS(pakfire_file_create(&file, t->root, "/bin/bash")); + ASSERT_SUCCESS(pakfire_file_create(&file, t->ctx, t->root, "/bin/bash")); // Append the file to the filelist ASSERT_SUCCESS(pakfire_filelist_add(filelist, file)); -- 2.47.2