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

index 4702281a83a153c9e32aa5bd980595e2d7db03c5..4158bbd7eca27891b28a5fd35feaad80ca359db8 100644 (file)
@@ -32,9 +32,6 @@
 #include <solv/repo.h>
 #include <solv/solvable.h>
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
 #include <pakfire/archive.h>
 #include <pakfire/constants.h>
 #include <pakfire/ctx.h>
@@ -161,14 +158,20 @@ static int pakfire_package_add_self_provides(struct pakfire_package* pkg) {
 
 int pakfire_package_create_from_solvable(struct pakfire_package** package,
                struct pakfire* pakfire, Id id) {
-       struct pakfire_package* pkg = calloc(1, sizeof(*pkg));
+       struct pakfire_package* pkg = NULL;
+
+       // Allocate some memory
+       pkg = calloc(1, sizeof(*pkg));
        if (!pkg)
-               return 1;
+               return -errno;
 
        // Store a reference to the context
        pkg->ctx = pakfire_ctx(pakfire);
 
+       // Store a reference to Pakfire
        pkg->pakfire = pakfire_ref(pakfire);
+
+       // Initialize the reference counter
        pkg->nrefs = 1;
 
        // Store the ID
@@ -176,6 +179,7 @@ int pakfire_package_create_from_solvable(struct pakfire_package** package,
 
        // Success
        *package = pkg;
+
        return 0;
 }
 
@@ -202,10 +206,13 @@ PAKFIRE_EXPORT int pakfire_package_create(struct pakfire_package** package,
                repo = dummy;
        }
 
+       // Fetch the context
+       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
        // Allocate a new solvable
        Id id = pakfire_repo_add_solvable(repo);
        if (!id) {
-               ERROR(pakfire, "Could not allocate a solvable: %m\n");
+               CTX_ERROR(ctx, "Could not allocate a solvable: %m\n");
                r = 1;
                goto ERROR;
        }
@@ -221,34 +228,36 @@ PAKFIRE_EXPORT int pakfire_package_create(struct pakfire_package** package,
        // Set the name
        r = pakfire_package_set_string(*package, PAKFIRE_PKG_NAME, name);
        if (r) {
-               ERROR(pakfire, "Could not set package name '%s': %m\n", name);
+               CTX_ERROR(ctx, "Could not set package name '%s': %m\n", name);
                goto ERROR;
        }
 
        // Set EVR
        r = pakfire_package_set_string(*package, PAKFIRE_PKG_EVR, evr);
        if (r) {
-               ERROR(pakfire, "Could not set package EVR '%s': %m\n", evr);
+               CTX_ERROR(ctx, "Could not set package EVR '%s': %m\n", evr);
                goto ERROR;
        }
 
        // Set arch
        r = pakfire_package_set_string(*package, PAKFIRE_PKG_ARCH, arch);
        if (r) {
-               ERROR(pakfire, "Could not set package arch '%s': %m\n", arch);
+               CTX_ERROR(ctx, "Could not set package arch '%s': %m\n", arch);
                goto ERROR;
        }
 
        // Add self-provides
        r = pakfire_package_add_self_provides(*package);
        if (r) {
-               ERROR(pakfire, "Could not create self-provides: %m\n");
+               CTX_ERROR(ctx, "Could not create self-provides: %m\n");
                goto ERROR;
        }
 
 ERROR:
        if (dummy)
                pakfire_repo_unref(dummy);
+       if (ctx)
+               pakfire_ctx_unref(ctx);
 
        return r;
 }
@@ -432,14 +441,14 @@ static int pakfire_package_make_cache_path(struct pakfire_package* pkg) {
        // Fetch the filename
        const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
        if (!filename) {
-               ERROR(pkg->pakfire, "Could not fetch filename for %s: %m\n", nevra);
+               CTX_ERROR(pkg->ctx, "Could not fetch filename for %s: %m\n", nevra);
                return 1;
        }
 
        // Fetch UUID
        const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
        if (!uuid) {
-               ERROR(pkg->pakfire, "Could not fetch UUID for %s: %m\n", nevra);
+               CTX_ERROR(pkg->ctx, "Could not fetch UUID for %s: %m\n", nevra);
                return 1;
        }
 
@@ -1821,7 +1830,7 @@ PAKFIRE_EXPORT struct pakfire_archive* pakfire_package_get_archive(struct pakfir
        // Open archive
        r = pakfire_archive_open(&archive, pkg->pakfire, path);
        if (r) {
-               ERROR(pkg->pakfire, "Could not open archive for %s (at %s): %m\n",
+               CTX_ERROR(pkg->ctx, "Could not open archive for %s (at %s): %m\n",
                        pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA), path);
                goto ERROR;
        }
@@ -1931,7 +1940,7 @@ int pakfire_package_append_file(struct pakfire_package* pkg, const char* path) {
        // Fetch repodata
        struct pakfire_repo* repo = pakfire_package_get_repo(pkg);
        if (!repo) {
-               ERROR(pkg->pakfire, "Could not find repository for %s: %m\n",
+               CTX_ERROR(pkg->ctx, "Could not find repository for %s: %m\n",
                        pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA));
                return 1;
        }
@@ -2140,7 +2149,7 @@ static int pakfire_package_add_json_filelist(
        // Fetch the filelist
        filelist = pakfire_package_get_filelist(pkg);
        if (!filelist) {
-               ERROR(pkg->pakfire, "Could not fetch package filelist\n");
+               CTX_ERROR(pkg->ctx, "Could not fetch package filelist\n");
                r = 1;
                goto ERROR;
        }
@@ -2148,7 +2157,7 @@ static int pakfire_package_add_json_filelist(
        // Create a new JSON array
        object = json_object_new_array();
        if (!object) {
-               ERROR(pkg->pakfire, "Could not create a JSON array\n");
+               CTX_ERROR(pkg->ctx, "Could not create a JSON array\n");
                r = 1;
                goto ERROR;
        }
@@ -2206,7 +2215,7 @@ static int pakfire_package_add_build_packages(struct pakfire_package* pkg,
        // Create a new JSON array
        object = json_object_new_object();
        if (!object) {
-               ERROR(pkg->pakfire, "Could not create a new JSON object: %m\n");
+               CTX_ERROR(pkg->ctx, "Could not create a new JSON object: %m\n");
                r = 1;
                goto ERROR;
        }
@@ -2214,7 +2223,7 @@ static int pakfire_package_add_build_packages(struct pakfire_package* pkg,
        // Fetch the installed repository
        repo = pakfire_get_installed_repo(pkg->pakfire);
        if (!repo) {
-               ERROR(pkg->pakfire, "Could not fetch the installed repository: %m\n");
+               CTX_ERROR(pkg->ctx, "Could not fetch the installed repository: %m\n");
                r = 1;
                goto ERROR;
        }
@@ -2227,7 +2236,7 @@ static int pakfire_package_add_build_packages(struct pakfire_package* pkg,
        // Fetch all installed packages
        r = pakfire_repo_to_packagelist(repo, packages);
        if (r) {
-               ERROR(pkg->pakfire, "Could not fetch packages from installed repository: %m\n");
+               CTX_ERROR(pkg->ctx, "Could not fetch packages from installed repository: %m\n");
                goto ERROR;
        }
 
@@ -2495,14 +2504,14 @@ PAKFIRE_EXPORT int pakfire_package_installcheck(struct pakfire_package* pkg,
        r = pakfire_transaction_request_package(transaction,
                PAKFIRE_JOB_INSTALL, pkg, PAKFIRE_JOB_ESSENTIAL);
        if (r) {
-               ERROR(pkg->pakfire, "Could not add package %s to the request\n", nevra);
+               CTX_ERROR(pkg->ctx, "Could not add package %s to the request\n", nevra);
                goto ERROR;
        }
 
        // Solve the transaction
        r = pakfire_transaction_solve(transaction, PAKFIRE_TRANSACTION_WITHOUT_RECOMMENDED, &p);
        if (r) {
-               DEBUG(pkg->pakfire, "Could not install %s:\n%s\n", nevra, p);
+               CTX_DEBUG(pkg->ctx, "Could not install %s:\n%s\n", nevra, p);
 
                // Copy the problem string
                if (p)