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

index e4ffdfcc24043966d9b5350a55620449d824dfcc..3572dbb691cba29122984b2be728b9c24642082a 100644 (file)
@@ -33,9 +33,6 @@
 
 #include <json.h>
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
 #include <pakfire/archive.h>
 #include <pakfire/compress.h>
 #include <pakfire/constants.h>
 #include <pakfire/util.h>
 
 struct pakfire_packager {
+       struct pakfire_ctx* ctx;
        struct pakfire* pakfire;
        int nrefs;
+
        time_t time_created;
 
        struct pakfire_package* pkg;
@@ -82,8 +81,12 @@ static void pakfire_packager_free(struct pakfire_packager* packager) {
 
        if (packager->filelist)
                pakfire_filelist_unref(packager->filelist);
-       pakfire_package_unref(packager->pkg);
-       pakfire_unref(packager->pakfire);
+       if (packager->pkg)
+               pakfire_package_unref(packager->pkg);
+       if (packager->pakfire)
+               pakfire_unref(packager->pakfire);
+       if (packager->ctx)
+               pakfire_ctx_unref(packager->ctx);
        free(packager);
 }
 
@@ -104,6 +107,9 @@ int pakfire_packager_create(struct pakfire_packager** packager,
        // Initialize reference counting
        p->nrefs = 1;
 
+       // Store a reference to the context
+       p->ctx = pakfire_ctx(pakfire);
+
        // Store a reference to Pakfire
        p->pakfire = pakfire_ref(pakfire);
 
@@ -116,7 +122,7 @@ int pakfire_packager_create(struct pakfire_packager** packager,
        // Set distribution
        const char* tag = pakfire_get_distro_tag(p->pakfire);
        if (!tag) {
-               ERROR(p->pakfire, "Distribution tag is not configured: %m\n");
+               CTX_ERROR(p->ctx, "Distribution tag is not configured: %m\n");
                goto ERROR;
        }
 
@@ -125,14 +131,14 @@ int pakfire_packager_create(struct pakfire_packager** packager,
        // Fetch the hostname
        r = gethostname(hostname, sizeof(hostname));
        if (r) {
-               ERROR(p->pakfire, "Could not determine the hostname: %m\n");
+               CTX_ERROR(p->ctx, "Could not determine the hostname: %m\n");
                goto ERROR;
        }
 
        // Set build host
        r = pakfire_package_set_string(pkg, PAKFIRE_PKG_BUILD_HOST, hostname);
        if (r) {
-               ERROR(p->pakfire, "Could not set the hostname: %s\n", strerror(r));
+               CTX_ERROR(p->ctx, "Could not set the hostname: %s\n", strerror(r));
                goto ERROR;
        }
 
@@ -269,21 +275,21 @@ static int pakfire_packager_write_file_from_buffer(struct pakfire_packager* pack
        // Create a new file
        struct archive_entry* entry = pakfire_packager_create_file(packager, filename, size, mode);
        if (!entry) {
-               ERROR(packager->pakfire, "Could not create file '%s'\n", filename);
+               CTX_ERROR(packager->ctx, "Could not create file '%s'\n", filename);
                return 1;
        }
 
        // This is the end of the header
        int r = archive_write_header(a, entry);
        if (r) {
-               ERROR(packager->pakfire, "Error writing header: %s\n", archive_error_string(a));
+               CTX_ERROR(packager->ctx, "Error writing header: %s\n", archive_error_string(a));
                goto ERROR;
        }
 
        // Write content
        r = archive_write_data(a, buffer, strlen(buffer));
        if (r < 0) {
-               ERROR(packager->pakfire, "Error writing data: %s\n", archive_error_string(a));
+               CTX_ERROR(packager->ctx, "Error writing data: %s\n", archive_error_string(a));
                goto ERROR;
        }
 
@@ -300,7 +306,7 @@ static int pakfire_packager_write_format(struct pakfire_packager* packager,
                struct archive* a) {
        const char buffer[] = TO_STRING(PACKAGE_FORMAT) "\n";
 
-       DEBUG(packager->pakfire, "Writing package format\n");
+       CTX_DEBUG(packager->ctx, "Writing package format\n");
 
        int r = pakfire_packager_write_file_from_buffer(packager, a,
                "pakfire-format", 0444, buffer);
@@ -349,7 +355,7 @@ static int pakfire_packager_write_metadata(struct pakfire_packager* packager,
        if (!buffer)
                return 1;
 
-       DEBUG(packager->pakfire, "Generated package metadata:\n%s\n", buffer);
+       CTX_DEBUG(packager->ctx, "Generated package metadata:\n%s\n", buffer);
 
        // Write buffer
        int r = pakfire_packager_write_file_from_buffer(packager, a,
@@ -369,7 +375,7 @@ static int pakfire_packager_write_scriptlet(struct pakfire_packager* packager,
        // Fetch type
        const char* type = pakfire_scriptlet_get_type(scriptlet);
 
-       DEBUG(packager->pakfire, "Writing scriptlet '%s' to package\n", type);
+       CTX_DEBUG(packager->ctx, "Writing scriptlet '%s' to package\n", type);
 
        // Make filename
        r = pakfire_string_format(filename, ".scriptlets/%s", type);
@@ -434,7 +440,7 @@ int pakfire_packager_finish(struct pakfire_packager* packager, FILE* f) {
        // Start with the format file
        r = pakfire_packager_write_format(packager, a);
        if (r) {
-               ERROR(packager->pakfire, "Could not add format file to archive: %s\n",
+               CTX_ERROR(packager->ctx, "Could not add format file to archive: %s\n",
                        archive_error_string(a));
                goto ERROR;
        }
@@ -442,7 +448,7 @@ int pakfire_packager_finish(struct pakfire_packager* packager, FILE* f) {
        // Write the metadata
        r = pakfire_packager_write_metadata(packager, a);
        if (r) {
-               ERROR(packager->pakfire, "Could not add metadata file to archive: %s\n",
+               CTX_ERROR(packager->ctx, "Could not add metadata file to archive: %s\n",
                        archive_error_string(a));
                goto ERROR;
        }
@@ -451,7 +457,7 @@ int pakfire_packager_finish(struct pakfire_packager* packager, FILE* f) {
        for (unsigned int i = 0; i < packager->num_scriptlets; i++) {
                r = pakfire_packager_write_scriptlet(packager, a, packager->scriptlets[i]);
                if (r) {
-                       ERROR(packager->pakfire, "Could not add scriptlet to the archive: %m\n");
+                       CTX_ERROR(packager->ctx, "Could not add scriptlet to the archive: %m\n");
                        goto ERROR;
                }
        }
@@ -491,7 +497,7 @@ int pakfire_packager_finish_to_directory(struct pakfire_packager* packager,
        // Get the filename of the package
        const char* filename = pakfire_packager_filename(packager);
        if (!filename) {
-               ERROR(packager->pakfire, "Could not generate filename for package: %m\n");
+               CTX_ERROR(packager->ctx, "Could not generate filename for package: %m\n");
                r = 1;
                goto ERROR;
        }
@@ -519,18 +525,18 @@ int pakfire_packager_finish_to_directory(struct pakfire_packager* packager,
        // Write the finished package
        r = pakfire_packager_finish(packager, f);
        if (r) {
-               ERROR(packager->pakfire, "pakfire_packager_finish() failed: %m\n");
+               CTX_ERROR(packager->ctx, "pakfire_packager_finish() failed: %m\n");
                goto ERROR;
        }
 
        // Move the temporary file to destination
        r = rename(tmppath, path);
        if (r) {
-               ERROR(packager->pakfire, "Could not move %s to %s: %m\n", tmppath, path);
+               CTX_ERROR(packager->ctx, "Could not move %s to %s: %m\n", tmppath, path);
                goto ERROR;
        }
 
-       DEBUG(packager->pakfire, "Package written to %s\n", path);
+       CTX_DEBUG(packager->ctx, "Package written to %s\n", path);
 
        // Store result path if requested
        if (result) {
@@ -569,18 +575,18 @@ int pakfire_packager_add_file(struct pakfire_packager* packager, struct pakfire_
 
        // Files cannot have an empty path
        if (!path || !*path) {
-               ERROR(packager->pakfire, "Cannot add a file with an empty path\n");
+               CTX_ERROR(packager->ctx, "Cannot add a file with an empty path\n");
                errno = EPERM;
                return 1;
 
        // Hidden files cannot be added
        } else if (*path == '.') {
-               ERROR(packager->pakfire, "Hidden files cannot be added to a package: %s\n", path);
+               CTX_ERROR(packager->ctx, "Hidden files cannot be added to a package: %s\n", path);
                errno = EPERM;
                return 1;
        }
 
-       DEBUG(packager->pakfire, "Adding file to payload: %s\n", path);
+       CTX_DEBUG(packager->ctx, "Adding file to payload: %s\n", path);
 
        // Detect the MIME type
        r = pakfire_file_detect_mimetype(file);
@@ -645,7 +651,7 @@ int pakfire_packager_add(struct pakfire_packager* packager,
        // Read everything
        r = archive_read_disk_entry_from_file(packager->reader, entry, -1, NULL);
        if (r) {
-               ERROR(packager->pakfire, "Could not read %s: %s\n",
+               CTX_ERROR(packager->ctx, "Could not read %s: %s\n",
                        sourcepath, archive_error_string(packager->reader));
                r = -errno;
                goto ERROR;
@@ -654,7 +660,7 @@ int pakfire_packager_add(struct pakfire_packager* packager,
        // Create a new file object from the archive entry
        r = pakfire_file_create_from_archive_entry(&file, packager->pakfire, entry);
        if (r < 0) {
-               ERROR(packager->pakfire, "Could not create file object: %s\n", strerror(-r));
+               CTX_ERROR(packager->ctx, "Could not create file object: %s\n", strerror(-r));
                goto ERROR;
        }