]> git.ipfire.org Git - pakfire.git/commitdiff
dist: Remove the legacy logger
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 14:11:15 +0000 (14:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 14:11:15 +0000 (14:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c

index 78b8d9bf71d191862a682b7a0ebb646fa9bdd883..c5dae34af962751b657999f2f8a88c22d1bbbf4f 100644 (file)
@@ -25,9 +25,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
 #include <pakfire/arch.h>
 #include <pakfire/dist.h>
 #include <pakfire/i18n.h>
@@ -157,6 +154,9 @@ int pakfire_read_makefile(struct pakfire_parser** parser, struct pakfire* pakfir
                const char* path, struct pakfire_parser_error** error) {
        int r = 1;
 
+       // Fetch context
+       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
        *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
        if (!*parser) {
                r = 1;
@@ -170,7 +170,7 @@ int pakfire_read_makefile(struct pakfire_parser** parser, struct pakfire* pakfir
 
        // Find all macros
 
-       DEBUG(pakfire, "Searching for macros in %s\n", PAKFIRE_MACROS_GLOB_PATTERN);
+       CTX_DEBUG(ctx, "Searching for macros in %s\n", PAKFIRE_MACROS_GLOB_PATTERN);
 
        glob_t globmacros;
        r = glob(PAKFIRE_MACROS_GLOB_PATTERN, 0, NULL, &globmacros);
@@ -189,11 +189,11 @@ int pakfire_read_makefile(struct pakfire_parser** parser, struct pakfire* pakfir
                        goto ERROR;
 
                default:
-                       ERROR(pakfire, "glob() returned an unhandled error: %d\n", r);
+                       CTX_ERROR(ctx, "glob() returned an unhandled error: %d\n", r);
                        goto ERROR;
        }
 
-       DEBUG(pakfire, "Found %zu macro(s)\n", globmacros.gl_pathc);
+       CTX_DEBUG(ctx, "Found %zu macro(s)\n", globmacros.gl_pathc);
 
        // Read all macros
        for (unsigned int i = 0; i < globmacros.gl_pathc; i++) {
@@ -208,7 +208,7 @@ int pakfire_read_makefile(struct pakfire_parser** parser, struct pakfire* pakfir
        // Finally, parse the makefile
        r = pakfire_parser_read_file(*parser, path, error);
        if (r) {
-               ERROR(pakfire, "Could not read makefile %s: %m\n", path);
+               CTX_ERROR(ctx, "Could not read makefile %s: %m\n", path);
                goto ERROR;
        }
 
@@ -222,12 +222,14 @@ ERROR:
                *parser = NULL;
        }
 
+       if (ctx)
+               pakfire_ctx_unref(ctx);
+
        return r;
 }
 
-static int pakfire_dist_get_mirrorlist(struct pakfire* pakfire,
+static int pakfire_dist_get_mirrorlist(struct pakfire_ctx* ctx, struct pakfire* pakfire,
                struct pakfire_parser* makefile, struct pakfire_mirrorlist** list) {
-       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
        struct pakfire_mirrorlist* m = NULL;
        struct pakfire_mirror* mirror = NULL;
        char* p = NULL;
@@ -243,7 +245,7 @@ static int pakfire_dist_get_mirrorlist(struct pakfire* pakfire,
        // Create mirrorlist
        r = pakfire_mirrorlist_create(&m, ctx);
        if (r) {
-               ERROR(pakfire, "Could not create the mirrorlist\n");
+               CTX_ERROR(ctx, "Could not create the mirrorlist\n");
                goto ERROR;
        }
 
@@ -270,8 +272,6 @@ static int pakfire_dist_get_mirrorlist(struct pakfire* pakfire,
 ERROR:
        if (m)
                pakfire_mirrorlist_unref(m);
-       if (ctx)
-               pakfire_ctx_unref(ctx);
        if (source_dl)
                free(source_dl);
 
@@ -349,8 +349,8 @@ static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packa
        return pakfire_packager_add(packager, cache_path, archive_path);
 }
 
-static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_packager* packager,
-               struct pakfire_package* pkg, struct pakfire_parser* makefile) {
+static int pakfire_dist_add_sources(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+               struct pakfire_packager* packager, struct pakfire_package* pkg, struct pakfire_parser* makefile) {
        struct pakfire_mirrorlist* mirrorlist = NULL;
        char* sources = NULL;
        char* p = NULL;
@@ -363,10 +363,8 @@ static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_pack
        if (!sources)
                return 0;
 
-       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
-
        // Fetch the mirrorlist
-       r = pakfire_dist_get_mirrorlist(pakfire, makefile, &mirrorlist);
+       r = pakfire_dist_get_mirrorlist(ctx, pakfire, makefile, &mirrorlist);
        if (r)
                goto ERROR;
 
@@ -374,11 +372,11 @@ static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_pack
        // Add all mirrors
        const char* source = strtok_r(sources, " ", &p);
        while (source) {
-               DEBUG(pakfire, "Adding source file %s\n", source);
+               CTX_DEBUG(ctx, "Adding source file %s\n", source);
 
                r = pakfire_dist_add_source(pakfire, packager, pkg, ctx, mirrorlist, source);
                if (r) {
-                       ERROR(pakfire, "Could not add '%s' to package: %m\n", source);
+                       CTX_ERROR(ctx, "Could not add '%s' to package: %m\n", source);
                        goto ERROR;
                }
 
@@ -391,8 +389,6 @@ static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_pack
 ERROR:
        if (mirrorlist)
                pakfire_mirrorlist_unref(mirrorlist);
-       if (ctx)
-               pakfire_ctx_unref(ctx);
        if (sources)
                free(sources);
 
@@ -414,7 +410,7 @@ static int __pakfire_dist_find_root(char* root, const size_t length, const char*
        return __pakfire_path_dirname(root, length, p);
 }
 
-static int pakfire_dist_add_files(struct pakfire* pakfire,
+static int pakfire_dist_add_files(struct pakfire_ctx* ctx, struct pakfire* pakfire,
                struct pakfire_packager* packager, const char* file) {
        struct pakfire_filelist* filelist = NULL;
        char root[PATH_MAX];
@@ -423,11 +419,11 @@ static int pakfire_dist_add_files(struct pakfire* pakfire,
        // Find the package directory
        r = pakfire_dist_find_root(root, file);
        if (r) {
-               ERROR(pakfire, "Could not find package root directory: %s\n", strerror(r));
+               CTX_ERROR(ctx, "Could not find package root directory: %s\n", strerror(r));
                return r;
        }
 
-       DEBUG(pakfire, "Adding all files in '%s' to package...\n", root);
+       CTX_DEBUG(ctx, "Adding all files in '%s' to package...\n", root);
 
        // Create a new filelist
        r = pakfire_filelist_create(&filelist, pakfire);
@@ -460,21 +456,24 @@ PAKFIRE_EXPORT int pakfire_dist(struct pakfire* pakfire, const char* path,
        struct pakfire_packager* packager = NULL;
        struct pakfire_package* pkg = NULL;
 
+       // Fetch context
+       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
        // Load makefile
        int r = pakfire_read_makefile(&makefile, pakfire, path, &error);
        if (r) {
                if (error)
                        pakfire_parser_error_unref(error);
                else
-                       ERROR(pakfire, "Could not read makefile: %m\n");
+                       CTX_ERROR(ctx, "Could not read makefile: %m\n");
 
-               return r;
+               goto ERROR;
        }
 
        // The architecture is always "src"
        r = pakfire_parser_set(makefile, NULL, "arch", "src", 0);
        if (r) {
-               ERROR(pakfire, "Could not set architecture to 'src': %m\n");
+               CTX_ERROR(ctx, "Could not set architecture to 'src': %m\n");
                goto ERROR;
        }
 
@@ -489,12 +488,12 @@ PAKFIRE_EXPORT int pakfire_dist(struct pakfire* pakfire, const char* path,
                goto ERROR;
 
        // Add all files in the directory
-       r = pakfire_dist_add_files(pakfire, packager, path);
+       r = pakfire_dist_add_files(ctx, pakfire, packager, path);
        if (r)
                goto ERROR;
 
        // Add all source files (which might need to be downloaded)
-       r = pakfire_dist_add_sources(pakfire, packager, pkg, makefile);
+       r = pakfire_dist_add_sources(ctx, pakfire, packager, pkg, makefile);
        if (r)
                goto ERROR;
 
@@ -510,7 +509,8 @@ ERROR:
                pakfire_packager_unref(packager);
        if (pkg)
                pakfire_package_unref(pkg);
-       pakfire_parser_unref(makefile);
+       if (makefile)
+               pakfire_parser_unref(makefile);
 
        return r;
 }