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

index 11a099e6274947513c8d8dc515c39bf92bcafd60..18136e8695740163ed56d618137a37844305dd9c 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/config.h>
@@ -187,9 +184,9 @@ char* pakfire_repo_url_replace(struct pakfire_repo* repo, const char* url) {
 
 #ifdef ENABLE_DEBUG
        if (strcmp(url, buffer) != 0) {
-               DEBUG(repo->pakfire, "Repository URL updated:");
-               DEBUG(repo->pakfire, "  From: %s\n", url);
-               DEBUG(repo->pakfire, "  To  : %s\n", buffer);
+               CTX_DEBUG(repo->ctx, "Repository URL updated:");
+               CTX_DEBUG(repo->ctx, "  From: %s\n", url);
+               CTX_DEBUG(repo->ctx, "  To  : %s\n", buffer);
        }
 #endif
 
@@ -289,16 +286,16 @@ static int pakfire_repo_import_key(struct pakfire_repo* repo, const char* data)
 
        // Import the key
        r = pakfire_key_import_from_string(&repo->key, repo->ctx, data, strlen(data));
-       if (r) {
-               ERROR(repo->pakfire, "Could not import key for repository '%s': %m\n",
-                       pakfire_repo_get_name(repo));
+       if (r < 0) {
+               CTX_ERROR(repo->ctx, "Could not import key for repository '%s': %s\n",
+                       pakfire_repo_get_name(repo), strerror(-r));
                goto ERROR;
        }
 
        // If the key could be successfully imported, we will store it in the appdata
        r = pakfire_string_set(repo->appdata->key, data);
-       if (r) {
-               ERROR(repo->pakfire, "Could not copy the key to appdata: %m\n");
+       if (r < 0) {
+               CTX_ERROR(repo->ctx, "Could not copy the key to appdata: %s\n", strerror(-r));
                goto ERROR;
        }
 
@@ -322,12 +319,15 @@ static int __pakfire_repo_import( struct pakfire_config* config, const char* sec
        if (!*name)
                return 0;
 
-       DEBUG(pakfire, "Creating repository %s\n", name);
+       // Fetch context
+       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
+       CTX_DEBUG(ctx, "Creating repository %s\n", name);
 
        // Create a new repository
        r = pakfire_repo_create(&repo, pakfire, name);
        if (r) {
-               ERROR(pakfire, "Could not create repository '%s': %m\n", name);
+               CTX_ERROR(ctx, "Could not create repository '%s': %m\n", name);
                goto ERROR;
        }
 
@@ -374,6 +374,8 @@ static int __pakfire_repo_import( struct pakfire_config* config, const char* sec
 ERROR:
        if (repo)
                pakfire_repo_unref(repo);
+       if (ctx)
+               pakfire_ctx_unref(ctx);
 
        return r;
 }
@@ -415,16 +417,16 @@ struct pakfire_mirrorlist* pakfire_repo_get_mirrorlist(struct pakfire_repo* repo
                        return NULL;
 
                int r = pakfire_mirrorlist_create(&repo->mirrorlist, repo->ctx);
-               if (r) {
-                       ERROR(repo->pakfire, "Could not create mirrorlist: %m\n");
+               if (r < 0) {
+                       CTX_ERROR(repo->ctx, "Could not create mirrorlist: %s\n", strerror(-r));
                        return NULL;
                }
 
                // Read the mirrorlist
                r = pakfire_mirrorlist_read(repo->mirrorlist, repo->appdata->mirrorlist);
-               if (r) {
-                       ERROR(repo->pakfire, "Could not read mirrorlist %s: %m\n",
-                               repo->appdata->mirrorlist);
+               if (r < 0) {
+                       CTX_ERROR(repo->ctx, "Could not read mirrorlist %s: %s\n",
+                               repo->appdata->mirrorlist, strerror(-r));
 
                        // Destroy what we have created
                        pakfire_mirrorlist_unref(repo->mirrorlist);
@@ -445,7 +447,7 @@ static int pakfire_repo_download_database(struct pakfire_repo* repo,
 
        // Do nothing if the file already exists
        if (pakfire_path_exists(path)) {
-               DEBUG(repo->pakfire, "Database %s already present. Skipping download\n", filename);
+               CTX_DEBUG(repo->ctx, "Database %s already present. Skipping download\n", filename);
                return 0;
        }
 
@@ -487,12 +489,12 @@ static int pakfire_repo_read_database(struct pakfire_repo* repo, const char* pat
        FILE* f = NULL;
        int r;
 
-       DEBUG(repo->pakfire, "Read package database from %s...\n", path);
+       CTX_DEBUG(repo->ctx, "Read package database from %s...\n", path);
 
        // Open the database file
        f = fopen(path, "r");
        if (!f) {
-               ERROR(repo->pakfire, "Could not open package database at %s: %m\n", path);
+               CTX_ERROR(repo->ctx, "Could not open package database at %s: %m\n", path);
                r = 1;
                goto ERROR;
        }
@@ -518,7 +520,7 @@ static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* pat
        char database_path[PATH_MAX];
        int r;
 
-       DEBUG(repo->pakfire, "Reading repository metadata from %s...\n", path);
+       CTX_DEBUG(repo->ctx, "Reading repository metadata from %s...\n", path);
 
        struct json_object* json = pakfire_json_parse_from_file(repo->ctx, path);
        if (!json) {
@@ -526,7 +528,7 @@ static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* pat
                        case ENOENT:
                                // If the repository is local, we will just scan it
                                if (pakfire_repo_is_local(repo)) {
-                                       DEBUG(repo->pakfire, "No metadata available on local repository."
+                                       CTX_DEBUG(repo->ctx, "No metadata available on local repository."
                                                " Falling back to scan...\n");
 
                                        return pakfire_repo_scan(repo, 0);
@@ -534,7 +536,7 @@ static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* pat
                                break;
                }
 
-               ERROR(repo->pakfire, "Could not parse metadata from %s: %m\n", path);
+               CTX_ERROR(repo->ctx, "Could not parse metadata from %s: %m\n", path);
                return 1;
        }
 
@@ -543,7 +545,7 @@ static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* pat
        // Search for the database name
        int found = json_object_object_get_ex(json, "database", &database);
        if (!found) {
-               ERROR(repo->pakfire, "Could not read database name from metadata\n");
+               CTX_ERROR(repo->ctx, "Could not read database name from metadata\n");
                r = 1;
                goto ERROR;
        }
@@ -602,7 +604,7 @@ static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int
                time_t age = pakfire_path_age(repo->appdata->mirrorlist);
 
                if (age > 0 && age < REFRESH_AGE_MIRRORLIST) {
-                       DEBUG(repo->pakfire, "Skip refreshing mirrorlist which is %lds old\n", age);
+                       CTX_DEBUG(repo->ctx, "Skip refreshing mirrorlist which is %lds old\n", age);
                        return 0;
                }
        }
@@ -610,7 +612,7 @@ static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int
        // Replace any variables in the URL
        url = pakfire_repo_url_replace(repo, repo->appdata->mirrorlist_url);
        if (!url) {
-               ERROR(repo->pakfire, "Could not expend the mirror list URL: %m\n");
+               CTX_ERROR(repo->ctx, "Could not expend the mirror list URL: %m\n");
                r = -errno;
                goto ERROR;
        }
@@ -662,7 +664,7 @@ static int pakfire_repo_download_metadata(struct pakfire_repo* repo, const char*
                time_t age = pakfire_path_age(path);
 
                if (age > 0 && age < refresh) {
-                       DEBUG(repo->pakfire, "Skip refreshing metadata which is %lds old\n", age);
+                       CTX_DEBUG(repo->ctx, "Skip refreshing metadata which is %lds old\n", age);
                        return 0;
                }
        }
@@ -787,14 +789,14 @@ PAKFIRE_EXPORT int pakfire_repo_create(struct pakfire_repo** repo,
        // Allocate a libsolv repository
        rep->repo = repo_create(pool, name);
        if (!rep->repo) {
-               ERROR(rep->pakfire, "Could not allocate repo: %m\n");
+               CTX_ERROR(rep->ctx, "Could not allocate repo: %m\n");
                goto ERROR;
        }
 
        // Allocate repository appdata
        rep->appdata = rep->repo->appdata = pakfire_repo_setup_appdata(rep);
        if (!rep->appdata) {
-               ERROR(rep->pakfire, "Could not setup repository appdata for %s\n", name);
+               CTX_ERROR(rep->ctx, "Could not setup repository appdata for %s\n", name);
                goto ERROR;
        }
 
@@ -1074,7 +1076,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f)
        if (description) {
                r = pakfire_config_set(config, section, "description", description);
                if (r) {
-                       ERROR(repo->pakfire, "Could not set description: %m\n");
+                       CTX_ERROR(repo->ctx, "Could not set description: %m\n");
                        goto ERROR;
                }
        }
@@ -1083,7 +1085,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f)
        if (!pakfire_repo_get_enabled(repo)) {
                r = pakfire_config_set(config, section, "enabled", "0");
                if (r) {
-                       ERROR(repo->pakfire, "Could not set enabled: %m\n");
+                       CTX_ERROR(repo->ctx, "Could not set enabled: %m\n");
                        goto ERROR;
                }
        }
@@ -1093,7 +1095,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f)
        if (baseurl) {
                r = pakfire_config_set(config, section, "baseurl", baseurl);
                if (r) {
-                       ERROR(repo->pakfire, "Could not set base URL: %m\n");
+                       CTX_ERROR(repo->ctx, "Could not set base URL: %m\n");
                        goto ERROR;
                }
        }
@@ -1105,7 +1107,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f)
                free(refresh);
 
                if (r) {
-                       ERROR(repo->pakfire, "Could not set refresh interval: %m\n");
+                       CTX_ERROR(repo->ctx, "Could not set refresh interval: %m\n");
                        goto ERROR;
                }
        }
@@ -1115,7 +1117,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f)
        if (mirrorlist) {
                r = pakfire_config_set(config, section, "mirrors", mirrorlist);
                if (r) {
-                       ERROR(repo->pakfire, "Could not set mirrors: %m\n");
+                       CTX_ERROR(repo->ctx, "Could not set mirrors: %m\n");
                        goto ERROR;
                }
        }
@@ -1125,7 +1127,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f)
        if (key) {
                r = pakfire_key_export(key, f, PAKFIRE_KEY_EXPORT_MODE_PUBLIC);
                if (r) {
-                       ERROR(repo->pakfire, "Could not export the key: %m\n");
+                       CTX_ERROR(repo->ctx, "Could not export the key: %m\n");
                        goto ERROR;
                }
 
@@ -1134,7 +1136,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f)
                if (buffer) {
                        r = pakfire_config_set_format(config, section, "key", "%.*s", (int)length, buffer);
                        if (r) {
-                               ERROR(repo->pakfire, "Could not set key: %m\n");
+                               CTX_ERROR(repo->ctx, "Could not set key: %m\n");
                                goto ERROR;
                        }
                }
@@ -1145,7 +1147,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_config(struct pakfire_repo* repo, FILE* f)
        if (priority) {
                r = pakfire_config_set_format(config, section, "priority", "%u", priority);
                if (r) {
-                       ERROR(repo->pakfire, "Could not set priority: %m\n");
+                       CTX_ERROR(repo->ctx, "Could not set priority: %m\n");
                        goto ERROR;
                }
        }
@@ -1195,14 +1197,14 @@ int pakfire_repo_download_package(struct pakfire_xfer** xfer,
        // Where do we store the package?
        cache_path = pakfire_package_get_string(pkg, PAKFIRE_PKG_CACHE_PATH);
        if (!cache_path) {
-               ERROR(repo->pakfire, "Could not retrieve package cache path for %s: %m\n", nevra);
+               CTX_ERROR(repo->ctx, "Could not retrieve package cache path for %s: %m\n", nevra);
                goto ERROR;
        }
 
        // Where do we find the package on the server?
        url = pakfire_package_get_string(pkg, PAKFIRE_PKG_PATH);
        if (!url) {
-               ERROR(repo->pakfire, "Could not retrieve package path for %s: %m\n", nevra);
+               CTX_ERROR(repo->ctx, "Could not retrieve package path for %s: %m\n", nevra);
                goto ERROR;
        }
 
@@ -1212,7 +1214,7 @@ int pakfire_repo_download_package(struct pakfire_xfer** xfer,
        // Retrieve package digest
        digest = pakfire_package_get_digest(pkg, &digest_type, &digest_length);
        if (!digest) {
-               ERROR(repo->pakfire, "Package %s has no digest set: %m\n", nevra);
+               CTX_ERROR(repo->ctx, "Package %s has no digest set: %m\n", nevra);
                goto ERROR;
        }
 
@@ -1315,7 +1317,7 @@ int pakfire_repo_add(struct pakfire_repo* repo, const char* path,
        if (pakfire_string_is_url(path)) {
                r = pakfire_repo_download(repo, path, package);
                if (r)
-                       ERROR(repo->pakfire, "Could not download %s\n", path);
+                       CTX_ERROR(repo->ctx, "Could not download %s\n", path);
 
                return r;
        }
@@ -1336,7 +1338,7 @@ int pakfire_repo_add(struct pakfire_repo* repo, const char* path,
                goto ERROR;
        }
 
-       DEBUG(repo->pakfire, "Added %s to repository '%s'\n",
+       CTX_DEBUG(repo->ctx, "Added %s to repository '%s'\n",
                nevra, pakfire_repo_get_name(repo));
 
 ERROR:
@@ -1399,8 +1401,8 @@ PAKFIRE_EXPORT int pakfire_repo_write_solv(struct pakfire_repo* repo, FILE *f, i
        // Create another repodata section for meta information
        meta = repo_add_repodata(repo->repo, 0);
        if (!meta) {
-               ERROR(repo->pakfire, "Could not create meta repodata: %m\n");
-               r = 1;
+               CTX_ERROR(repo->ctx, "Could not create meta repodata: %m\n");
+               r = -errno;
                goto ERROR;
        }
 
@@ -1432,7 +1434,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_solv(struct pakfire_repo* repo, FILE *f, i
        // Flush buffers
        r = fflush(f);
        if (r) {
-               ERROR(repo->pakfire, "Could not flush after writing repository: %m\n");
+               CTX_ERROR(repo->ctx, "Could not flush after writing repository: %m\n");
                goto ERROR;
        }
 
@@ -1468,13 +1470,12 @@ static int pakfire_repo_delete_all_packages(
                if (prefix && !pakfire_string_startswith(path, prefix))
                        goto NEXT;
 
-               DEBUG(repo->pakfire, "Removing %s at %s\n", nevra, path);
+               CTX_DEBUG(repo->ctx, "Removing %s at %s\n", nevra, path);
 
                // Delete the file
                r = unlink(path);
                if (r) {
-                       ERROR(repo->pakfire, "Could not unlink %s at %s: %m\n",
-                               nevra, path);
+                       CTX_ERROR(repo->ctx, "Could not unlink %s at %s: %m\n", nevra, path);
                }
 
 NEXT:
@@ -1666,14 +1667,14 @@ PAKFIRE_EXPORT int pakfire_repo_refresh(struct pakfire_repo* repo, int force) {
        // Do nothing if this repository is not enabled
        int enabled = pakfire_repo_get_enabled(repo);
        if (!enabled) {
-               DEBUG(repo->pakfire, "Skip refreshing repository '%s'\n", name);
+               CTX_DEBUG(repo->ctx, "Skip refreshing repository '%s'\n", name);
                return 0;
        }
 
        // Refresh mirrorlist
        r = pakfire_repo_refresh_mirrorlist(repo, force);
        if (r) {
-               ERROR(repo->pakfire, "Could not refresh mirrorlist, but will continue anyways...\n");
+               CTX_ERROR(repo->ctx, "Could not refresh mirrorlist, but will continue anyways...\n");
        }
 
        // Refresh metadata
@@ -1695,7 +1696,7 @@ static int pakfire_repo_sign_database(struct pakfire_repo* repo, struct pakfire_
        // Open the signature file for writing
        s = fopen(signature_path, "w");
        if (!s) {
-               ERROR(repo->pakfire, "Could not open %s for writing: %m\n", signature_path);
+               CTX_ERROR(repo->ctx, "Could not open %s for writing: %m\n", signature_path);
                r = 1;
                goto ERROR;
        }
@@ -1703,7 +1704,7 @@ static int pakfire_repo_sign_database(struct pakfire_repo* repo, struct pakfire_
        // Open the database for reading
        f = fopen(database_path, "r");
        if (!f) {
-               ERROR(repo->pakfire, "Could not open %s for reading: %m\n", database_path);
+               CTX_ERROR(repo->ctx, "Could not open %s for reading: %m\n", database_path);
                r = 1;
                goto ERROR;
        }
@@ -1711,7 +1712,7 @@ static int pakfire_repo_sign_database(struct pakfire_repo* repo, struct pakfire_
        // Create the signature
        r = pakfire_key_signf(key, s, f, "Database Signature");
        if (r) {
-               ERROR(repo->pakfire, "Could not sign the database: %m\n");
+               CTX_ERROR(repo->ctx, "Could not sign the database: %m\n");
                goto ERROR;
        }
 
@@ -1738,21 +1739,21 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, struct pakfire
        // Create a temporary file to write to
        FILE* f = pakfire_mktemp(tmp, 0644);
        if (!f) {
-               ERROR(repo->pakfire, "Could not open temporary file for writing: %m\n");
+               CTX_ERROR(repo->ctx, "Could not open temporary file for writing: %m\n");
                return 1;
        }
 
        // Initialize the output being compressed
        f = pakfire_zstdfopen(f, "w");
        if (!f) {
-               ERROR(repo->pakfire, "Could not initialize compression: %m\n");
+               CTX_ERROR(repo->ctx, "Could not initialize compression: %m\n");
                return 1;
        }
 
        // Write the SOLV database to the temporary file
        r = pakfire_repo_write_solv(repo, f, 0);
        if (r) {
-               ERROR(repo->pakfire, "Could not write SOLV data: %m\n");
+               CTX_ERROR(repo->ctx, "Could not write SOLV data: %m\n");
                goto ERROR;
        }
 
@@ -1763,21 +1764,21 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, struct pakfire
        // Create a filename for the database file
        r = __pakfire_strftime_now(filename, length, "%Y-%m-%d-%H%M.%s.solv.zst");
        if (r) {
-               ERROR(repo->pakfire, "Could not format database filename: %m\n");
+               CTX_ERROR(repo->ctx, "Could not format database filename: %m\n");
                goto ERROR;
        }
 
        // Make final database path
        r = pakfire_string_format(database, "%s/repodata/%s", path, filename);
        if (r) {
-               ERROR(repo->pakfire, "Could not join database path: %m\n");
+               CTX_ERROR(repo->ctx, "Could not join database path: %m\n");
                goto ERROR;
        }
 
        // Link database to its destination
        r = link(tmp, database);
        if (r) {
-               ERROR(repo->pakfire, "Could not link database %s: %m\n", database);
+               CTX_ERROR(repo->ctx, "Could not link database %s: %m\n", database);
                goto ERROR;
        }
 
@@ -1785,7 +1786,7 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, struct pakfire
        if (key) {
                r = pakfire_repo_sign_database(repo, key, database);
                if (r) {
-                       ERROR(repo->pakfire, "Could not sign the database: %m\n");
+                       CTX_ERROR(repo->ctx, "Could not sign the database: %m\n");
                        goto ERROR;
                }
        }
@@ -1826,7 +1827,7 @@ static int pakfire_repo_write_metadata(struct pakfire_repo* repo, struct pakfire
        // Compose JSON object
        repomd = json_object_new_object();
        if (!repomd) {
-               ERROR(repo->pakfire, "Could not allocate a new JSON object: %m\n");
+               CTX_ERROR(repo->ctx, "Could not allocate a new JSON object: %m\n");
                r = 1;
                goto ERROR;
        }
@@ -1834,14 +1835,14 @@ static int pakfire_repo_write_metadata(struct pakfire_repo* repo, struct pakfire
        // Set version
        struct json_object* repomd_version = json_object_new_int64(0);
        if (!repomd_version) {
-               ERROR(repo->pakfire, "Could not create version: %m\n");
+               CTX_ERROR(repo->ctx, "Could not create version: %m\n");
                r = 1;
                goto ERROR;
        }
 
        r = json_object_object_add(repomd, "version", repomd_version);
        if (r) {
-               ERROR(repo->pakfire, "Could not add version to repomd.json: %m\n");
+               CTX_ERROR(repo->ctx, "Could not add version to repomd.json: %m\n");
                goto ERROR;
        }
 
@@ -1850,28 +1851,28 @@ static int pakfire_repo_write_metadata(struct pakfire_repo* repo, struct pakfire
        // Set revision
        struct json_object* repomd_revision = json_object_new_int64(revision);
        if (!repomd_revision) {
-               ERROR(repo->pakfire, "Could not create revision: %m\n");
+               CTX_ERROR(repo->ctx, "Could not create revision: %m\n");
                r = 1;
                goto ERROR;
        }
 
        r = json_object_object_add(repomd, "revision", repomd_revision);
        if (r) {
-               ERROR(repo->pakfire, "Could not add revision to repomd.json: %m\n");
+               CTX_ERROR(repo->ctx, "Could not add revision to repomd.json: %m\n");
                goto ERROR;
        }
 
        // Set database
        struct json_object* repomd_database = json_object_new_string(database);
        if (!repomd_database) {
-               ERROR(repo->pakfire, "Could not create database string: %m\n");
+               CTX_ERROR(repo->ctx, "Could not create database string: %m\n");
                r = 1;
                goto ERROR;
        }
 
        r = json_object_object_add(repomd, "database", repomd_database);
        if (r) {
-               ERROR(repo->pakfire, "Could not add database to repomd.json: %m\n");
+               CTX_ERROR(repo->ctx, "Could not add database to repomd.json: %m\n");
                goto ERROR;
        }
 
@@ -1887,7 +1888,7 @@ static int pakfire_repo_write_metadata(struct pakfire_repo* repo, struct pakfire
        // Open repomd.json for writing
        f = fopen(repomd_path, "w");
        if (!f) {
-               ERROR(repo->pakfire, "Could not open %s for writing: %m\n", repomd_path);
+               CTX_ERROR(repo->ctx, "Could not open %s for writing: %m\n", repomd_path);
                r = 1;
                goto ERROR;
        }
@@ -1895,7 +1896,7 @@ static int pakfire_repo_write_metadata(struct pakfire_repo* repo, struct pakfire
        // Write out repomd.json
        r = json_object_to_fd(fileno(f), repomd, JSON_C_TO_STRING_PRETTY);
        if (r) {
-               ERROR(repo->pakfire, "Could not write repomd.json: %m\n");
+               CTX_ERROR(repo->ctx, "Could not write repomd.json: %m\n");
                goto ERROR;
        }
 
@@ -1923,6 +1924,9 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
                return 1;
        }
 
+       // Fetch context
+       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
        // XXX Check if the key is a secret key
 
        size_t num_files = 0;
@@ -1939,7 +1943,7 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
        // Make path absolute
        r = pakfire_path_realpath(realpath, path);
        if (r)
-               return r;
+               goto ERROR;
 
        // Prefix path with file:// to form baseurl
        r = pakfire_string_format(baseurl, "file://%s", realpath);
@@ -1949,21 +1953,21 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
        // Create a new temporary repository at path
        r = pakfire_repo_create(&repo, pakfire, "tmp");
        if (r) {
-               ERROR(pakfire, "Could not create a temporary repository: %m\n");
+               CTX_ERROR(ctx, "Could not create a temporary repository: %m\n");
                goto ERROR;
        }
 
        // Set baseurl to path
        r = pakfire_repo_set_baseurl(repo, baseurl);
        if (r) {
-               ERROR(pakfire, "Could not set baseurl %s: %m\n", baseurl);
+               CTX_ERROR(ctx, "Could not set baseurl %s: %m\n", baseurl);
                goto ERROR;
        }
 
        // Find everything that is already part of the repository
        r = pakfire_repo_scan(repo, 0);
        if (r) {
-               ERROR(pakfire, "Could not refresh repository: %m\n");
+               CTX_ERROR(ctx, "Could not refresh repository: %m\n");
                goto ERROR;
        }
 
@@ -1974,31 +1978,31 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
        char destination_path[PATH_MAX];
        char repo_path[PATH_MAX];
 
-       DEBUG(pakfire, "Adding %zu file(s) to the repository\n", num_files);
+       CTX_DEBUG(ctx, "Adding %zu file(s) to the repository\n", num_files);
 
        // Add more files
        if (files) {
                for (const char** file = files; *file; file++) {
-                       DEBUG(pakfire, "Adding %s to repository...\n", *file);
+                       CTX_DEBUG(ctx, "Adding %s to repository...\n", *file);
 
                        // Open source archive
                        r = pakfire_archive_open(&archive, pakfire, *file);
                        if (r) {
-                               ERROR(pakfire, "Could not open %s: %m\n", *file);
+                               CTX_ERROR(ctx, "Could not open %s: %m\n", *file);
                                goto OUT;
                        }
 
                        // Add package metadata
                        r = pakfire_repo_add_archive(repo, archive, &package);
                        if (r) {
-                               ERROR(pakfire, "Could not add %s to the repository: %m\n", *file);
+                               CTX_ERROR(ctx, "Could not add %s to the repository: %m\n", *file);
                                goto OUT;
                        }
 
                        // Fetch the UUID
                        uuid = pakfire_package_get_string(package, PAKFIRE_PKG_UUID);
                        if (!uuid) {
-                               ERROR(pakfire, "Could not retrieve the UUID of %s: %m\n", *file);
+                               CTX_ERROR(ctx, "Could not retrieve the UUID of %s: %m\n", *file);
                                r = -EINVAL;
                                goto OUT;
                        }
@@ -2006,7 +2010,7 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
                        // Fetch the filename
                        filename = pakfire_package_get_string(package, PAKFIRE_PKG_FILENAME);
                        if (!filename) {
-                               ERROR(pakfire, "Could not retrieve filename of %s: %m\n", *file);
+                               CTX_ERROR(ctx, "Could not retrieve filename of %s: %m\n", *file);
                                r = -EINVAL;
                                goto OUT;
                        }
@@ -2024,7 +2028,7 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
                        // Copying archive to destination
                        r = pakfire_archive_link_or_copy(archive, destination_path);
                        if (r) {
-                               ERROR(pakfire, "Could not copy archive to %s: %m\n", destination_path);
+                               CTX_ERROR(ctx, "Could not copy archive to %s: %m\n", destination_path);
                                goto OUT;
                        }
 
@@ -2059,6 +2063,8 @@ ERROR:
                pakfire_repo_clear(repo);
                pakfire_repo_unref(repo);
        }
+       if (ctx)
+               pakfire_ctx_unref(ctx);
 
        return r;
 }