]> git.ipfire.org Git - pakfire.git/commitdiff
dist: Directly pass the context
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 13:09:34 +0000 (13:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 13:09:34 +0000 (13:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/dist.c
src/pakfire/build.c
src/pakfire/dist.c
src/pakfire/dist.h
src/pakfire/root.c
src/python/root.c
tests/libpakfire/makefile.c

index 2c111e39afc5c9babe497a06152fcb55594bf049..001d651228700479e306c6b80bbca5858302f21d 100644 (file)
@@ -60,14 +60,15 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
        return 0;
 }
 
-static int do_dist(pakfire_root* root, const char* makefile, const char* resultdir) {
+static int do_dist(pakfire_ctx* ctx, pakfire_root* root, const char* makefile,
+               const char* resultdir) {
        pakfire_archive* archive = NULL;
        const char* filename = NULL;
        char path[PATH_MAX];
        int r;
 
        // Create the archive
-       r = pakfire_dist(root, makefile, &archive);
+       r = pakfire_dist(ctx, root, makefile, &archive);
        if (r < 0)
                goto ERROR;
 
@@ -119,7 +120,7 @@ int cli_dist(void* data, int argc, char* argv[]) {
 
        // Process all packages
        for (unsigned int i = 0; i < local_args.num_makefiles; i++) {
-               r = do_dist(root, local_args.makefiles[i], local_args.resultdir);
+               r = do_dist(global_args->ctx, root, local_args.makefiles[i], local_args.resultdir);
                if (r < 0) {
                        fprintf(stderr, "Could not dist %s: %s\n", local_args.makefiles[i], strerror(-r));
                        goto ERROR;
index e26ccba17a6631ba3b77cc9d421bbbfe77923687..474c7740f3e95f323e6f07d0c6cf53232bb4a847 100644 (file)
@@ -2204,7 +2204,7 @@ static int pakfire_build_read_makefile(pakfire_build* build,
                return 1;
 
        // Read makefile
-       r = pakfire_read_makefile(parser, build->root, path, &error);
+       r = pakfire_read_makefile(parser, build->ctx, build->root, path, &error);
        if (r) {
                if (error) {
                        ERROR(build->ctx, "Could not parse makefile %s: %s\n", path,
index 6effe6ad22f1fccde875453aeb5a1c3994e75d9d..415fc83549932cbc1d8a3e7fb49f0dcf22b08224 100644 (file)
@@ -149,13 +149,10 @@ static int pakfire_makefile_set_defaults(pakfire_root* root,
        return 0;
 }
 
-int pakfire_read_makefile(pakfire_parser** parser, pakfire_root* root,
+int pakfire_read_makefile(pakfire_parser** parser, pakfire_ctx* ctx, pakfire_root* root,
                const char* path, pakfire_parser_error** error) {
        int r;
 
-       // Fetch context
-       pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
        // Create a new parser
        r = pakfire_parser_create(parser, root, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
        if (r < 0)
@@ -211,9 +208,6 @@ int pakfire_read_makefile(pakfire_parser** parser, pakfire_root* root,
                goto ERROR;
        }
 
-       if (ctx)
-               pakfire_ctx_unref(ctx);
-
        return 0;
 
 ERROR:
@@ -224,9 +218,6 @@ ERROR:
                *parser = NULL;
        }
 
-       if (ctx)
-               pakfire_ctx_unref(ctx);
-
        return r;
 }
 
@@ -450,7 +441,7 @@ ERROR:
        return r;
 }
 
-int pakfire_dist(pakfire_root* root, const char* path, pakfire_archive** archive) {
+int pakfire_dist(pakfire_ctx* ctx, pakfire_root* root, const char* path, pakfire_archive** archive) {
        pakfire_packager* packager = NULL;
        pakfire_package* pkg = NULL;
        pakfire_parser* makefile = NULL;
@@ -458,11 +449,8 @@ int pakfire_dist(pakfire_root* root, const char* path, pakfire_archive** archive
        pakfire_archive* a = NULL;
        int r;
 
-       // Fetch context
-       pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
        // Load makefile
-       r = pakfire_read_makefile(&makefile, root, path, &error);
+       r = pakfire_read_makefile(&makefile, ctx, root, path, &error);
        if (r < 0) {
                if (error)
                        pakfire_parser_error_unref(error);
@@ -521,8 +509,6 @@ ERROR:
                pakfire_parser_unref(makefile);
        if (a)
                pakfire_archive_unref(a);
-       if (ctx)
-               pakfire_ctx_unref(ctx);
 
        return r;
 }
index b5debf31039b9be035f091375636cf420e1fe3bc..4eb52fc1c418a8e715b323bb853ff9d9d79aa138 100644 (file)
 #define PAKFIRE_DIST_H
 
 #include <pakfire/archive.h>
+#include <pakfire/ctx.h>
 #include <pakfire/root.h>
 #include <pakfire/parser.h>
 
-int pakfire_dist(pakfire_root* root, const char* path, pakfire_archive** archive);
+int pakfire_dist(pakfire_ctx* ctx, pakfire_root* root,
+       const char* path, pakfire_archive** archive);
 
-int pakfire_read_makefile(pakfire_parser** parser, pakfire_root* root,
-       const char* path, pakfire_parser_error** error);
+int pakfire_read_makefile(pakfire_parser** parser,
+       pakfire_ctx* ctx, pakfire_root* root, const char* path, pakfire_parser_error** error);
 
 #endif /* PAKFIRE_DIST_H */
index 97703ee9b7ad6a04e8d23a46fdf9f7009fd19f24..0aea2f308d2b4b2dbeff127217747f299f6c15e8 100644 (file)
@@ -1449,7 +1449,7 @@ static int pakfire_root_commandline_dist(pakfire_root* self,
        int r;
 
        // Run dist()
-       r = pakfire_dist(self, path, &archive);
+       r = pakfire_dist(self->ctx, self, path, &archive);
        if (r < 0)
                goto ERROR;
 
index 666a1c59ac650e1883ff62b2b338dccf8e5a8d13..21290a177de0c5543ea685316d976015c1873e7d 100644 (file)
@@ -369,7 +369,7 @@ static PyObject* Root_dist(RootObject* self, PyObject* args) {
 
        Py_BEGIN_ALLOW_THREADS
 
-       r = pakfire_dist(self->root, path, &archive);
+       r = pakfire_dist(self->ctx->ctx, self->root, path, &archive);
        if (r) {
                Py_BLOCK_THREADS
                PyErr_SetFromErrno(PyExc_OSError);
index 823c435544859020a084c3f803bad28340660a48..a35a91d229e8d53dc91b82ed791f8994c8d5e2ed 100644 (file)
@@ -181,7 +181,7 @@ static int test_dist_dummy(const struct test* t) {
        ASSERT(tmp);
 
        // Attempt to dist the dummy package
-       ASSERT_SUCCESS(pakfire_dist(t->root,
+       ASSERT_SUCCESS(pakfire_dist(t->ctx, t->root,
                TEST_SRC_PATH "data/packages/dummy/dummy.nm", &archive));
 
        // Extract all package metadata