From: Michael Tremer Date: Sun, 29 Jun 2025 13:09:34 +0000 (+0000) Subject: dist: Directly pass the context X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57d3133044293059541712e541e60324bc5313d7;p=pakfire.git dist: Directly pass the context Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/dist.c b/src/cli/lib/dist.c index 2c111e39..001d6512 100644 --- a/src/cli/lib/dist.c +++ b/src/cli/lib/dist.c @@ -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; diff --git a/src/pakfire/build.c b/src/pakfire/build.c index e26ccba1..474c7740 100644 --- a/src/pakfire/build.c +++ b/src/pakfire/build.c @@ -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, diff --git a/src/pakfire/dist.c b/src/pakfire/dist.c index 6effe6ad..415fc835 100644 --- a/src/pakfire/dist.c +++ b/src/pakfire/dist.c @@ -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; } diff --git a/src/pakfire/dist.h b/src/pakfire/dist.h index b5debf31..4eb52fc1 100644 --- a/src/pakfire/dist.h +++ b/src/pakfire/dist.h @@ -22,12 +22,14 @@ #define PAKFIRE_DIST_H #include +#include #include #include -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 */ diff --git a/src/pakfire/root.c b/src/pakfire/root.c index 97703ee9..0aea2f30 100644 --- a/src/pakfire/root.c +++ b/src/pakfire/root.c @@ -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; diff --git a/src/python/root.c b/src/python/root.c index 666a1c59..21290a17 100644 --- a/src/python/root.c +++ b/src/python/root.c @@ -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); diff --git a/tests/libpakfire/makefile.c b/tests/libpakfire/makefile.c index 823c4355..a35a91d2 100644 --- a/tests/libpakfire/makefile.c +++ b/tests/libpakfire/makefile.c @@ -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