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

index c1a0703ba596beff6e4b92e5845686a4010e184a..631ffeab67b6b9ad8615d18707ee3af83cf5bf70 100644 (file)
@@ -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;
 
index 9b7a19d7e1c1cecf50c0cdc5af8eed6e1ba9d91a..f617b38b559b8a38269d57d5971c35786340cd18 100644 (file)
@@ -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;
 
index 61f585e6224b951fa1249e582af6754ed15206de..8dbee5c97fa5d45e15165badc19e864905a94059 100644 (file)
@@ -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;
 
index 6b86ac0e87d0983327a3e89cd7a31ab86ac61756..14afe9b4b66140376d4308e6637fb3f24b0304b1 100644 (file)
@@ -32,6 +32,7 @@
 
 typedef struct pakfire_file pakfire_file;
 
+#include <pakfire/ctx.h>
 #include <pakfire/hashes.h>
 #include <pakfire/root.h>
 
@@ -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 {
index c91718fd85fcef73aa04ee84e0d57bc3bf6812da..4c0040f6a46ec3a49a494686f4d78b4b1fee284b 100644 (file)
@@ -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;
 
index d44ac1beb4befef9a59cfc28141fa89c65967ee4..3088c596b727eab8eddae80d39cbf693945a6b92 100644 (file)
@@ -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;
 
index 6e6a23b6f1002be86989a4e324c28deeda3bfd81..5f4248fa1ee3c4adabb5cb7a3ca47369649d8700 100644 (file)
@@ -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,
index 4e55e8d1ee988a3d8d4bf149fb1454051065e838..d6afd2fcc63a7a280de79d807263ca3ca268506f 100644 (file)
@@ -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;
index 8a1c2eeae1da1e6f25e9af0fcc1c6c023866b3c9..cc89096bc78a89da4c48e20f82faeaf9817ffbc4 100644 (file)
@@ -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;
 
index 8fae33f837a0e13fd592f72edfb69b5fbf1bba40..4a0a8f98ab056667cce31499af3dfa371c27d593 100644 (file)
@@ -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));
index 7f403308c73d7d43bbb02012db04c48a1a8a9fec..71a73412ea37bea9ac2dfcb5f8903ba95d07794c 100644 (file)
@@ -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));