]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
libpakfire: db: Replace legacy logger
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Jan 2024 17:15:31 +0000 (17:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Jan 2024 17:15:31 +0000 (17:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/db.c

index f64b82bbf076d444ca5eea4ab42c328ccb9c3e21..bfc2b76ff53b35f6387cbceb12e8e73f8da3b808 100644 (file)
@@ -27,9 +27,6 @@
 #include <solv/solver.h>
 #include <sqlite3.h>
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
 #include <pakfire/archive.h>
 #include <pakfire/ctx.h>
 #include <pakfire/db.h>
@@ -63,9 +60,9 @@ struct pakfire_db {
 };
 
 static void logging_callback(void* data, int r, const char* msg) {
-       struct pakfire* pakfire = (struct pakfire*)data;
+       struct pakfire_ctx* ctx = data;
 
-       ERROR(pakfire, "Database Error: %s: %s\n",
+       CTX_ERROR(ctx, "Database Error: %s: %s\n",
                sqlite3_errstr(r), msg);
 }
 
@@ -78,7 +75,7 @@ static int pakfire_db_check_table(struct pakfire_db* db, const char* table) {
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto ERROR;
        }
@@ -86,14 +83,14 @@ static int pakfire_db_check_table(struct pakfire_db* db, const char* table) {
        // Bind type
        r = sqlite3_bind_text(stmt, 1, "table", -1, NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
        // Bind name
        r = sqlite3_bind_text(stmt, 2, table, -1, NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not bind name: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind name: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -133,7 +130,7 @@ static sqlite3_value* pakfire_db_get(struct pakfire_db* db, const char* key) {
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r != SQLITE_OK) {
-               //ERROR(db->pakfire, "Could not prepare SQL statement: %s: %s\n",
+               //CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
                //      sql, sqlite3_errmsg(db->handle));
                return NULL;
        }
@@ -141,7 +138,7 @@ static sqlite3_value* pakfire_db_get(struct pakfire_db* db, const char* key) {
        // Bind key
        r = sqlite3_bind_text(stmt, 1, key, strlen(key), NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -157,7 +154,7 @@ static sqlite3_value* pakfire_db_get(struct pakfire_db* db, const char* key) {
        // Read value
        val = sqlite3_column_value(stmt, 0);
        if (!val) {
-               ERROR(db->pakfire, "Could not read value\n");
+               CTX_ERROR(db->ctx, "Could not read value\n");
                goto ERROR;
        }
 
@@ -198,7 +195,7 @@ static int pakfire_db_set_string(struct pakfire_db* db, const char* key, const c
        sqlite3_stmt* stmt = NULL;
        int r;
 
-       DEBUG(db->pakfire, "Setting %s to '%s'\n", key, val);
+       CTX_DEBUG(db->ctx, "Setting %s to '%s'\n", key, val);
 
        const char* sql = "INSERT INTO settings(key, val) VALUES(?, ?) \
                ON CONFLICT (key) DO UPDATE SET val = excluded.val";
@@ -206,7 +203,7 @@ static int pakfire_db_set_string(struct pakfire_db* db, const char* key, const c
        // Prepare statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
                        sql, sqlite3_errmsg(db->handle));
                return 1;
        }
@@ -214,14 +211,14 @@ static int pakfire_db_set_string(struct pakfire_db* db, const char* key, const c
        // Bind key
        r = sqlite3_bind_text(stmt, 1, key, strlen(key), NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
        // Bind val
        r = sqlite3_bind_text(stmt, 2, val, strlen(val), NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not bind val: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind val: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -244,7 +241,7 @@ static int pakfire_db_set_int(struct pakfire_db* db, const char* key, int val) {
        sqlite3_stmt* stmt = NULL;
        int r;
 
-       DEBUG(db->pakfire, "Setting %s to '%d'\n", key, val);
+       CTX_DEBUG(db->ctx, "Setting %s to '%d'\n", key, val);
 
        const char* sql = "INSERT INTO settings(key, val) VALUES(?, ?) \
                ON CONFLICT (key) DO UPDATE SET val = excluded.val";
@@ -252,7 +249,7 @@ static int pakfire_db_set_int(struct pakfire_db* db, const char* key, int val) {
        // Prepare statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
                        sql, sqlite3_errmsg(db->handle));
                return 1;
        }
@@ -260,14 +257,14 @@ static int pakfire_db_set_int(struct pakfire_db* db, const char* key, int val) {
        // Bind key
        r = sqlite3_bind_text(stmt, 1, key, strlen(key), NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
        // Bind val
        r = sqlite3_bind_int64(stmt, 2, val);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not bind val: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind val: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -295,7 +292,7 @@ static time_t pakfire_read_modification_time(struct pakfire_db* db) {
                t = sqlite3_value_int64(value);
                sqlite3_value_free(value);
        } else {
-               DEBUG(db->pakfire, "Could not find last modification timestamp\n");
+               CTX_DEBUG(db->ctx, "Could not find last modification timestamp\n");
        }
 
        return t;
@@ -319,7 +316,7 @@ static int pakfire_update_modification_time(struct pakfire_db* db) {
 static int pakfire_db_execute(struct pakfire_db* db, const char* stmt) {
        int r;
 
-       DEBUG(db->pakfire, "Executing database query: %s\n", stmt);
+       CTX_DEBUG(db->ctx, "Executing database query: %s\n", stmt);
 
        do {
                r = sqlite3_exec(db->handle, stmt, NULL, NULL, NULL);
@@ -327,7 +324,7 @@ static int pakfire_db_execute(struct pakfire_db* db, const char* stmt) {
 
        // Log any errors
        if (r) {
-               ERROR(db->pakfire, "Database query failed: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Database query failed: %s\n", sqlite3_errmsg(db->handle));
        }
 
        return r;
@@ -373,7 +370,7 @@ static void pakfire_db_free(struct pakfire_db* db) {
                // Close database handle
                int r = sqlite3_close(db->handle);
                if (r != SQLITE_OK) {
-                       ERROR(db->pakfire, "Could not close database handle: %s\n",
+                       CTX_ERROR(db->ctx, "Could not close database handle: %s\n",
                                sqlite3_errmsg(db->handle));
                }
        }
@@ -394,7 +391,7 @@ static int pakfire_db_get_schema(struct pakfire_db* db) {
        int schema = sqlite3_value_int64(value);
        sqlite3_value_free(value);
 
-       DEBUG(db->pakfire, "Database has schema version %d\n", schema);
+       CTX_DEBUG(db->ctx, "Database has schema version %d\n", schema);
 
        return schema;
 }
@@ -528,7 +525,7 @@ static int pakfire_db_create_schema(struct pakfire_db* db) {
        // Set architecture
        r = pakfire_db_set_string(db, "arch", arch);
        if (r) {
-               ERROR(db->pakfire, "Could not set architecture\n");
+               CTX_ERROR(db->ctx, "Could not set architecture\n");
                return r;
        }
 
@@ -573,7 +570,7 @@ static int pakfire_db_migrate_schema(struct pakfire_db* db) {
                                break;
 
                        default:
-                               ERROR(db->pakfire, "Cannot migrate database from schema %d\n", db->schema);
+                               CTX_ERROR(db->ctx, "Cannot migrate database from schema %d\n", db->schema);
                                goto ROLLBACK;
                }
 
@@ -602,7 +599,7 @@ static int pakfire_db_check_arch(struct pakfire_db* db) {
        // Fetch database architecture
        char* db_arch = pakfire_db_get_string(db, "arch");
        if (!db_arch) {
-               ERROR(db->pakfire, "Database is of an unknown architecture\n");
+               CTX_ERROR(db->ctx, "Database is of an unknown architecture\n");
                goto ERROR;
        }
 
@@ -626,7 +623,7 @@ static int pakfire_db_setup(struct pakfire_db* db) {
        int r;
 
        // Setup logging
-       sqlite3_config(SQLITE_CONFIG_LOG, logging_callback, db->pakfire);
+       sqlite3_config(SQLITE_CONFIG_LOG, logging_callback, db->ctx);
 
        // Enable foreign keys
        pakfire_db_execute(db, "PRAGMA foreign_keys = ON");
@@ -639,7 +636,7 @@ static int pakfire_db_setup(struct pakfire_db* db) {
 
        // Check if the schema is recent enough
        if (db->schema && db->schema < SCHEMA_MIN_SUP) {
-               ERROR(db->pakfire, "Database schema %d is not supported by this version of Pakfire\n",
+               CTX_ERROR(db->ctx, "Database schema %d is not supported by this version of Pakfire\n",
                        db->schema);
                return 1;
        }
@@ -647,7 +644,7 @@ static int pakfire_db_setup(struct pakfire_db* db) {
        // Read modification timestamp
        db->last_modified_at = pakfire_read_modification_time(db);
 
-       DEBUG(db->pakfire, "The database was last modified at %ld\n", db->last_modified_at);
+       CTX_DEBUG(db->ctx, "The database was last modified at %ld\n", db->last_modified_at);
 
        // Done when not in read-write mode
        if (db->mode != PAKFIRE_DB_READWRITE)
@@ -659,7 +656,7 @@ static int pakfire_db_setup(struct pakfire_db* db) {
        // Set database journal to WAL
        r = pakfire_db_execute(db, "PRAGMA journal_mode = WAL");
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not set journal mode to WAL: %s\n",
+               CTX_ERROR(db->ctx, "Could not set journal mode to WAL: %s\n",
                        sqlite3_errmsg(db->handle));
                return 1;
        }
@@ -667,7 +664,7 @@ static int pakfire_db_setup(struct pakfire_db* db) {
        // Disable autocheckpoint
        r = sqlite3_wal_autocheckpoint(db->handle, 0);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not disable autocheckpoint: %s\n",
+               CTX_ERROR(db->ctx, "Could not disable autocheckpoint: %s\n",
                        sqlite3_errmsg(db->handle));
                return 1;
        }
@@ -712,7 +709,7 @@ int pakfire_db_open(struct pakfire_db** db, struct pakfire* pakfire, int flags)
        // Try to open the sqlite3 database file
        r = sqlite3_open_v2(o->path, &o->handle, sqlite3_flags, NULL);
        if (r != SQLITE_OK) {
-               ERROR(pakfire, "Could not open database %s: %s\n",
+               CTX_ERROR(o->ctx, "Could not open database %s: %s\n",
                        o->path, sqlite3_errmsg(o->handle));
 
                r = 1;
@@ -760,7 +757,7 @@ static unsigned long pakfire_db_integrity_check(struct pakfire_db* db) {
 
        r = sqlite3_prepare_v2(db->handle, "PRAGMA integrity_check", -1, &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare integrity check: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare integrity check: %s\n",
                        sqlite3_errmsg(db->handle));
                return 1;
        }
@@ -784,7 +781,7 @@ static unsigned long pakfire_db_integrity_check(struct pakfire_db* db) {
                        errors++;
 
                        // Log the message
-                       ERROR(db->pakfire, "%s\n", error);
+                       CTX_ERROR(db->ctx, "%s\n", error);
 
                // Break on anything else
                } else
@@ -794,9 +791,9 @@ static unsigned long pakfire_db_integrity_check(struct pakfire_db* db) {
        sqlite3_finalize(stmt);
 
        if (errors)
-               ERROR(db->pakfire, "Database integrity check failed\n");
+               CTX_ERROR(db->ctx, "Database integrity check failed\n");
        else
-               INFO(db->pakfire, "Database integrity check passed\n");
+               CTX_INFO(db->ctx, "Database integrity check passed\n");
 
        return errors;
 }
@@ -807,7 +804,7 @@ static unsigned long pakfire_db_foreign_key_check(struct pakfire_db* db) {
 
        r = sqlite3_prepare_v2(db->handle, "PRAGMA foreign_key_check", -1, &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare foreign key check: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare foreign key check: %s\n",
                        sqlite3_errmsg(db->handle));
                return 1;
        }
@@ -830,7 +827,7 @@ static unsigned long pakfire_db_foreign_key_check(struct pakfire_db* db) {
                        errors++;
 
                        // Log the message
-                       ERROR(db->pakfire, "Foreign key violation found in %s, row %lu: "
+                       CTX_ERROR(db->ctx, "Foreign key violation found in %s, row %lu: "
                                "%lu does not exist in table %s\n", table, rowid, foreign_rowid, foreign_table);
 
                // Break on anything else
@@ -841,9 +838,9 @@ static unsigned long pakfire_db_foreign_key_check(struct pakfire_db* db) {
        sqlite3_finalize(stmt);
 
        if (errors)
-               ERROR(db->pakfire, "Foreign key check failed\n");
+               CTX_ERROR(db->ctx, "Foreign key check failed\n");
        else
-               INFO(db->pakfire, "Foreign key check passed\n");
+               CTX_INFO(db->ctx, "Foreign key check passed\n");
 
        return errors;
 }
@@ -874,7 +871,7 @@ ssize_t pakfire_db_packages(struct pakfire_db* db) {
 
        int r = sqlite3_prepare_v2(db->handle, "SELECT COUNT(*) FROM packages", -1, &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s\n",
                        sqlite3_errmsg(db->handle));
                return -1;
        }
@@ -913,7 +910,7 @@ static int pakfire_db_add_dependencies(struct pakfire_db* db, unsigned long id,
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, -1, &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto END;
        }
@@ -929,7 +926,7 @@ static int pakfire_db_add_dependencies(struct pakfire_db* db, unsigned long id,
                        // Bind package ID
                        r = sqlite3_bind_int64(stmt, 1, id);
                        if (r) {
-                               ERROR(db->pakfire, "Could not bind id: %s\n",
+                               CTX_ERROR(db->ctx, "Could not bind id: %s\n",
                                        sqlite3_errmsg(db->handle));
                                goto END;
                        }
@@ -937,7 +934,7 @@ static int pakfire_db_add_dependencies(struct pakfire_db* db, unsigned long id,
                        // Bind type
                        r = sqlite3_bind_text(stmt, 2, dep->name, -1, NULL);
                        if (r) {
-                               ERROR(db->pakfire, "Could not bind type: %s\n",
+                               CTX_ERROR(db->ctx, "Could not bind type: %s\n",
                                        sqlite3_errmsg(db->handle));
                                goto END;
                        }
@@ -945,7 +942,7 @@ static int pakfire_db_add_dependencies(struct pakfire_db* db, unsigned long id,
                        // Bind dependency
                        r = sqlite3_bind_text(stmt, 3, *d, -1, NULL);
                        if (r) {
-                               ERROR(db->pakfire, "Could not bind dependency: %s\n",
+                               CTX_ERROR(db->ctx, "Could not bind dependency: %s\n",
                                        sqlite3_errmsg(db->handle));
                                goto END;
                        }
@@ -998,7 +995,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
        // Get the filelist from the archive
        struct pakfire_filelist* filelist = pakfire_archive_get_filelist(archive);
        if (!filelist) {
-               ERROR(db->pakfire, "Could not fetch filelist from archive\n");
+               CTX_ERROR(db->ctx, "Could not fetch filelist from archive\n");
                return 1;
        }
 
@@ -1035,7 +1032,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto END;
        }
@@ -1046,7 +1043,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // Bind package ID
                r = sqlite3_bind_int64(stmt, 1, id);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind id: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind id: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1056,7 +1053,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
 
                r = sqlite3_bind_text(stmt, 2, path, -1, NULL);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind path: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind path: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1066,7 +1063,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
 
                r = sqlite3_bind_int64(stmt, 3, size);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind size: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind size: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1074,7 +1071,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // Bind config - XXX TODO
                r = sqlite3_bind_null(stmt, 4);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind config: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind config: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1082,7 +1079,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // Bind datafile - XXX TODO
                r = sqlite3_bind_null(stmt, 5);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind datafile: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind datafile: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1092,7 +1089,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
 
                r = sqlite3_bind_int64(stmt, 6, mode);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind mode: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind mode: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1102,7 +1099,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
 
                r = sqlite3_bind_text(stmt, 7, uname, -1, NULL);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind uname: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind uname: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1112,7 +1109,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
 
                r = sqlite3_bind_text(stmt, 8, gname, -1, NULL);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind gname: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind gname: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1122,7 +1119,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
 
                r = sqlite3_bind_int64(stmt, 9, ctime);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind ctime: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind ctime: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1132,7 +1129,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
 
                r = sqlite3_bind_int64(stmt, 10, mtime);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind mtime: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind mtime: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1143,7 +1140,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                if (mimetype) {
                        r = sqlite3_bind_text(stmt, 11, mimetype, -1, NULL);
                        if (r) {
-                               ERROR(db->pakfire, "Could not bind MIME type: %s\n",
+                               CTX_ERROR(db->ctx, "Could not bind MIME type: %s\n",
                                        sqlite3_errmsg(db->handle));
                                pakfire_file_unref(file);
                                goto END;
@@ -1151,7 +1148,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                } else {
                        r = sqlite3_bind_null(stmt, 11);
                        if (r) {
-                               ERROR(db->pakfire, "Could not bind an empty MIME type: %s\n",
+                               CTX_ERROR(db->ctx, "Could not bind an empty MIME type: %s\n",
                                        sqlite3_errmsg(db->handle));
                                pakfire_file_unref(file);
                                goto END;
@@ -1161,7 +1158,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // Bind capabilities - XXX TODO
                r = sqlite3_bind_null(stmt, 12);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind capabilities: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind capabilities: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
                }
@@ -1169,7 +1166,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // SHA2-512 Digest
                r = pakfire_db_bind_digest(db, stmt, 13, file, PAKFIRE_DIGEST_SHA2_512);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind SHA2-512 digest: %s\n",
+                       CTX_ERROR(db->ctx, "Could not bind SHA2-512 digest: %s\n",
                                sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
@@ -1178,7 +1175,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // SHA2-256 Digest
                r = pakfire_db_bind_digest(db, stmt, 14, file, PAKFIRE_DIGEST_SHA2_256);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind SHA2-256 digest: %s\n",
+                       CTX_ERROR(db->ctx, "Could not bind SHA2-256 digest: %s\n",
                                sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
@@ -1187,7 +1184,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // BLAKE2b512 Digest
                r = pakfire_db_bind_digest(db, stmt, 15, file, PAKFIRE_DIGEST_BLAKE2B512);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind BLAKE2b512 digest: %s\n",
+                       CTX_ERROR(db->ctx, "Could not bind BLAKE2b512 digest: %s\n",
                                sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
@@ -1196,7 +1193,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // BLAKE2s256 Digest
                r = pakfire_db_bind_digest(db, stmt, 16, file, PAKFIRE_DIGEST_BLAKE2S256);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind BLAKE2s256 digest: %s\n",
+                       CTX_ERROR(db->ctx, "Could not bind BLAKE2s256 digest: %s\n",
                                sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
@@ -1205,7 +1202,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // SHA3-512 Digest
                r = pakfire_db_bind_digest(db, stmt, 17, file, PAKFIRE_DIGEST_SHA3_512);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind SHA3-512 digest: %s\n",
+                       CTX_ERROR(db->ctx, "Could not bind SHA3-512 digest: %s\n",
                                sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
@@ -1214,7 +1211,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
                // SHA3-256 Digest
                r = pakfire_db_bind_digest(db, stmt, 18, file, PAKFIRE_DIGEST_SHA3_256);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind SHA3-256 digest: %s\n",
+                       CTX_ERROR(db->ctx, "Could not bind SHA3-256 digest: %s\n",
                                sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
@@ -1227,7 +1224,7 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
 
                // Check for errors
                if (r != SQLITE_DONE) {
-                       ERROR(db->pakfire, "Could not add file to database: %s\n",
+                       CTX_ERROR(db->ctx, "Could not add file to database: %s\n",
                                sqlite3_errmsg(db->handle));
                        pakfire_file_unref(file);
                        goto END;
@@ -1261,7 +1258,7 @@ static int pakfire_db_add_scriptlets(struct pakfire_db* db, unsigned long id, st
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, -1, &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto END;
        }
@@ -1275,7 +1272,7 @@ static int pakfire_db_add_scriptlets(struct pakfire_db* db, unsigned long id, st
                // Bind package ID
                r = sqlite3_bind_int64(stmt, 1, id);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind id: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind id: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_scriptlet_unref(scriptlet);
                        goto END;
                }
@@ -1283,7 +1280,7 @@ static int pakfire_db_add_scriptlets(struct pakfire_db* db, unsigned long id, st
                // Bind handle
                r = sqlite3_bind_text(stmt, 2, *type, -1, NULL);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_scriptlet_unref(scriptlet);
                        goto END;
                }
@@ -1293,7 +1290,7 @@ static int pakfire_db_add_scriptlets(struct pakfire_db* db, unsigned long id, st
                // Bind scriptlet
                r = sqlite3_bind_text(stmt, 3, data, size, NULL);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind scriptlet: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind scriptlet: %s\n", sqlite3_errmsg(db->handle));
                        pakfire_scriptlet_unref(scriptlet);
                        goto END;
                }
@@ -1305,7 +1302,7 @@ static int pakfire_db_add_scriptlets(struct pakfire_db* db, unsigned long id, st
 
                // Check for errors
                if (r != SQLITE_DONE) {
-                       ERROR(db->pakfire, "Could not add scriptlet to database: %s\n",
+                       CTX_ERROR(db->ctx, "Could not add scriptlet to database: %s\n",
                                sqlite3_errmsg(db->handle));
                        pakfire_scriptlet_unref(scriptlet);
                        goto END;
@@ -1394,7 +1391,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r != SQLITE_OK) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto ERROR;
        }
@@ -1404,7 +1401,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 1, name, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind name: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind name: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1413,7 +1410,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 2, evr, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind evr: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind evr: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1422,7 +1419,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 3, arch, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind arch: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind arch: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1438,7 +1435,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
                r = sqlite3_bind_text(stmt, 4, __groups, -1, NULL);
                if (r) {
-                       ERROR(db->pakfire, "Could not bind groups: %s\n", sqlite3_errmsg(db->handle));
+                       CTX_ERROR(db->ctx, "Could not bind groups: %s\n", sqlite3_errmsg(db->handle));
                        goto ERROR;
                }
 
@@ -1454,7 +1451,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 5, filename, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind filename: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind filename: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1463,7 +1460,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_int64(stmt, 6, size);
        if (r) {
-               ERROR(db->pakfire, "Could not bind size: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind size: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1472,7 +1469,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_int64(stmt, 7, inst_size);
        if (r) {
-               ERROR(db->pakfire, "Could not bind inst_size: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind inst_size: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1483,7 +1480,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
        // Fetch the digest
        digest = pakfire_package_get_digest(pkg, &digest_type, &digest_length);
        if (!digest) {
-               ERROR(db->pakfire, "Could not fetch the package's digest: %m\n");
+               CTX_ERROR(db->ctx, "Could not fetch the package's digest: %m\n");
                r = 1;
                goto ERROR;
        }
@@ -1491,14 +1488,14 @@ int pakfire_db_add_package(struct pakfire_db* db,
        // Set the digest type
        r = sqlite3_bind_int64(stmt, 8, digest_type);
        if (r) {
-               ERROR(db->pakfire, "Could not bind digest type: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind digest type: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
        // Set the digest
        r = sqlite3_bind_blob(stmt, 9, digest, digest_length, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind digest: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind digest: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1507,7 +1504,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 10, license, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind license: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind license: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1516,7 +1513,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 11, summary, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind summary: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind summary: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1525,7 +1522,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 12, description, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind description: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind description: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1534,7 +1531,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 13, uuid, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1543,7 +1540,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 14, vendor, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind vendor: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind vendor: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1552,7 +1549,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_text(stmt, 15, build_host, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind build_host: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind build_host: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1561,7 +1558,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
 
        r = sqlite3_bind_int64(stmt, 16, build_time);
        if (r) {
-               ERROR(db->pakfire, "Could not bind build_time: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind build_time: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1585,7 +1582,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
        // installed by the user?
        r = sqlite3_bind_int(stmt, 18, userinstalled);
        if (r) {
-               ERROR(db->pakfire, "Could not bind userinstalled: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind userinstalled: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1643,7 +1640,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
        } while (r == SQLITE_BUSY);
 
        if (r != SQLITE_DONE) {
-               ERROR(db->pakfire, "Could not add package to database: %s\n",
+               CTX_ERROR(db->ctx, "Could not add package to database: %s\n",
                        sqlite3_errmsg(db->handle));
                r = 1;
                goto ERROR;
@@ -1696,7 +1693,7 @@ int pakfire_db_remove_package(struct pakfire_db* db, struct pakfire_package* pkg
        // Fetch the package's UUID
        const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
        if (!uuid) {
-               ERROR(db->pakfire, "Package has no UUID\n");
+               CTX_ERROR(db->ctx, "Package has no UUID\n");
                r = 1;
                goto ERROR;
        }
@@ -1704,7 +1701,7 @@ int pakfire_db_remove_package(struct pakfire_db* db, struct pakfire_package* pkg
        r = sqlite3_prepare_v2(db->handle,
                "DELETE FROM packages WHERE uuid = ?", -1, &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s\n",
                        sqlite3_errmsg(db->handle));
                goto ERROR;
        }
@@ -1712,7 +1709,7 @@ int pakfire_db_remove_package(struct pakfire_db* db, struct pakfire_package* pkg
        // Bind UUID
        r = sqlite3_bind_text(stmt, 1, uuid, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
@@ -1723,7 +1720,7 @@ int pakfire_db_remove_package(struct pakfire_db* db, struct pakfire_package* pkg
 
        // Check if we have been successful
        if (r != SQLITE_DONE) {
-               ERROR(db->pakfire, "Could not delete package %s\n", uuid);
+               CTX_ERROR(db->ctx, "Could not delete package %s\n", uuid);
                r = 1;
                goto ERROR;
        }
@@ -1753,7 +1750,7 @@ struct pakfire_scriptlet* pakfire_db_get_scriptlet(struct pakfire_db* db,
        // Fetch the package's UUID
        const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
        if (!uuid) {
-               ERROR(db->pakfire, "Package has no UUID\n");
+               CTX_ERROR(db->ctx, "Package has no UUID\n");
                goto ERROR;
        }
 
@@ -1763,7 +1760,7 @@ struct pakfire_scriptlet* pakfire_db_get_scriptlet(struct pakfire_db* db,
 
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto ERROR;
        }
@@ -1771,17 +1768,17 @@ struct pakfire_scriptlet* pakfire_db_get_scriptlet(struct pakfire_db* db,
        // Bind UUID
        r = sqlite3_bind_text(stmt, 1, uuid, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
        r = sqlite3_bind_text(stmt, 2, type, -1, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
-       DEBUG(db->pakfire, "Searching for scriptlet for package %s of type %s\n", uuid, type);
+       CTX_DEBUG(db->ctx, "Searching for scriptlet for package %s of type %s\n", uuid, type);
 
        // Execute query
        do {
@@ -1813,28 +1810,28 @@ static int pakfire_db_load_package(struct pakfire_db* db, struct pakfire_repo* r
        // Name
        const char* name = (const char*)sqlite3_column_text(stmt, 0);
        if (!name) {
-               ERROR(db->pakfire, "Could not read name: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not read name: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
        // EVR
        const char* evr = (const char*)sqlite3_column_text(stmt, 1);
        if (!evr) {
-               ERROR(db->pakfire, "Could not read evr: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not read evr: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
        // Arch
        const char* arch = (const char*)sqlite3_column_text(stmt, 2);
        if (!arch) {
-               ERROR(db->pakfire, "Could not read arch: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not read arch: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }
 
        // Create package
        r = pakfire_package_create(&pkg, db->pakfire, repo, name, evr, arch);
        if (r) {
-               ERROR(db->pakfire, "Could not create package '%s-%s.%s': %m\n", name, evr, arch);
+               CTX_ERROR(db->ctx, "Could not create package '%s-%s.%s': %m\n", name, evr, arch);
                goto ERROR;
        }
 
@@ -2040,7 +2037,7 @@ int pakfire_db_load(struct pakfire_db* db, struct pakfire_repo* repo) {
        sqlite3_stmt* stmt = NULL;
        int r = 1;
 
-       DEBUG(db->pakfire, "Loading package database...\n");
+       CTX_DEBUG(db->ctx, "Loading package database...\n");
 
        // Drop contents of the repository
        pakfire_repo_clear(repo);
@@ -2120,7 +2117,7 @@ int pakfire_db_load(struct pakfire_db* db, struct pakfire_repo* repo) {
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto ERROR;
        }
@@ -2155,7 +2152,7 @@ END:
        // Save time when we finished
        t_end = clock();
 
-       DEBUG(db->pakfire, "Loading package database completed in %.4fms\n",
+       CTX_DEBUG(db->ctx, "Loading package database completed in %.4fms\n",
                (double)(t_end - t_start) * 1000 / CLOCKS_PER_SEC);
 
        // Mark repository as changed
@@ -2166,7 +2163,7 @@ END:
 
 ERROR:
        if (r) {
-               ERROR(db->pakfire, "Failed reading package database: %m\n");
+               CTX_ERROR(db->ctx, "Failed reading package database: %m\n");
                pakfire_repo_clear(repo);
        }
 
@@ -2208,7 +2205,7 @@ static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist*
 
        // Abort if no path is set
        if (!path) {
-               ERROR(db->pakfire, "File has no path\n");
+               CTX_ERROR(db->ctx, "File has no path\n");
                r = 1;
                goto ERROR;
        }
@@ -2216,21 +2213,21 @@ static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist*
        // Set path
        r = pakfire_file_set_path(file, path);
        if (r) {
-               ERROR(db->pakfire, "%s: Could not set path '%s': %m\n", path, path);
+               CTX_ERROR(db->ctx, "%s: Could not set path '%s': %m\n", path, path);
                goto ERROR;
        }
 
        // Make the absolute path
        r = pakfire_path(db->pakfire, abspath, "%s", path);
        if (r) {
-               ERROR(db->pakfire, "%s: Could not make absolute path: %m\n", path);
+               CTX_ERROR(db->ctx, "%s: Could not make absolute path: %m\n", path);
                goto ERROR;
        }
 
        // Set the absolute path
        r = pakfire_file_set_abspath(file, abspath);
        if (r) {
-               ERROR(db->pakfire, "%s: Could not set absolute path %s: %m\n", path, abspath);
+               CTX_ERROR(db->ctx, "%s: Could not set absolute path %s: %m\n", path, abspath);
                goto ERROR;
        }
 
@@ -2249,7 +2246,7 @@ static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist*
 
        // Abort if no user is set
        if (!uname) {
-               ERROR(db->pakfire, "%s: No user\n", path);
+               CTX_ERROR(db->ctx, "%s: No user\n", path);
                r = 1;
                goto ERROR;
        }
@@ -2257,7 +2254,7 @@ static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist*
        // Set uname
        r = pakfire_file_set_uname(file, uname);
        if (r) {
-               ERROR(db->pakfire, "%s: Could not set user '%s': %m\n", path, uname);
+               CTX_ERROR(db->ctx, "%s: Could not set user '%s': %m\n", path, uname);
                goto ERROR;
        }
 
@@ -2266,7 +2263,7 @@ static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist*
 
        // Abort if no group is set
        if (!gname) {
-               ERROR(db->pakfire, "%s: No group\n", path);
+               CTX_ERROR(db->ctx, "%s: No group\n", path);
                r = 1;
                goto ERROR;
        }
@@ -2274,7 +2271,7 @@ static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist*
        // Set gname
        r = pakfire_file_set_gname(file, gname);
        if (r) {
-               ERROR(db->pakfire, "%s: Could not set group '%s': %m\n", path, gname);
+               CTX_ERROR(db->ctx, "%s: Could not set group '%s': %m\n", path, gname);
                goto ERROR;
        }
 
@@ -2365,7 +2362,7 @@ int pakfire_db_filelist(struct pakfire_db* db, struct pakfire_filelist** filelis
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto ERROR;
        }
@@ -2409,7 +2406,7 @@ END:
 
 ERROR:
        if (r)
-               ERROR(db->pakfire, "Could not fetch filelist: %m\n");
+               CTX_ERROR(db->ctx, "Could not fetch filelist: %m\n");
 
        if (stmt)
                sqlite3_finalize(stmt);
@@ -2428,14 +2425,14 @@ int pakfire_db_package_filelist(struct pakfire_db* db, struct pakfire_filelist**
        // Fetch the package ID
        uint64_t id = pakfire_package_get_num(pkg, PAKFIRE_PKG_DBID, 0);
        if (!id) {
-               ERROR(db->pakfire, "Package did not have an ID\n");
+               CTX_ERROR(db->ctx, "Package did not have an ID\n");
                return 1;
        }
 
        // Create a new filelist
        r = pakfire_filelist_create(&fl, db->pakfire);
        if (r) {
-               ERROR(db->pakfire, "Could not create filelist: %m\n");
+               CTX_ERROR(db->ctx, "Could not create filelist: %m\n");
                goto ERROR;
        }
 
@@ -2481,7 +2478,7 @@ int pakfire_db_package_filelist(struct pakfire_db* db, struct pakfire_filelist**
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
        if (r) {
-               ERROR(db->pakfire, "Could not prepare SQL statement: %s %s\n",
+               CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
                        sql, sqlite3_errmsg(db->handle));
                goto ERROR;
        }
@@ -2489,7 +2486,7 @@ int pakfire_db_package_filelist(struct pakfire_db* db, struct pakfire_filelist**
        // Bind package ID
        r = sqlite3_bind_int64(stmt, 1, id);
        if (r) {
-               ERROR(db->pakfire, "Could not bind package ID: %s\n", sqlite3_errmsg(db->handle));
+               CTX_ERROR(db->ctx, "Could not bind package ID: %s\n", sqlite3_errmsg(db->handle));
                goto ERROR;
        }