From: Michael Tremer Date: Mon, 29 Jan 2024 18:12:14 +0000 (+0000) Subject: compress: Remove legacy logger X-Git-Url: http://git.ipfire.org/?p=pakfire.git;a=commitdiff_plain compress: Remove legacy logger Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/compress.c b/src/libpakfire/compress.c index 8df636d7..22cb9fd7 100644 --- a/src/libpakfire/compress.c +++ b/src/libpakfire/compress.c @@ -27,9 +27,6 @@ #include #include -// Enable legacy logging -#define PAKFIRE_LEGACY_LOGGING - #include #include #include @@ -809,7 +806,7 @@ int pakfire_extract(struct pakfire* pakfire, struct archive* archive, if (!dry_run) { data.writer = pakfire_make_archive_disk_writer(pakfire, 1); if (!data.writer) { - ERROR(pakfire, "Could not create disk writer: %m\n"); + CTX_ERROR(ctx, "Could not create disk writer: %m\n"); r = 1; goto ERROR; } @@ -866,6 +863,9 @@ ERROR: // Common compression struct pakfire_compress { + // Reference to context + struct pakfire_ctx* ctx; + // Reference to Pakfire struct pakfire* pakfire; @@ -888,7 +888,7 @@ struct pakfire_compress { int digests; }; -static int pakfire_copy_data_from_file(struct pakfire* pakfire, +static int pakfire_copy_data_from_file(struct pakfire_ctx* ctx, struct archive* archive, FILE* f) { char buffer[BUFFER_SIZE]; @@ -905,14 +905,14 @@ static int pakfire_copy_data_from_file(struct pakfire* pakfire, // Check if any error occured if (ferror(f)) { - ERROR(pakfire, "Read error: %m\n"); + CTX_ERROR(ctx, "Read error: %m\n"); return -errno; } // Write the block to the archive bytes_written = archive_write_data(archive, buffer, bytes_read); if (bytes_written < bytes_read) { - ERROR(pakfire, "Write error: %s\n", archive_error_string(archive)); + CTX_ERROR(ctx, "Write error: %s\n", archive_error_string(archive)); return -errno; } } @@ -936,7 +936,7 @@ static int __pakfire_compress_entry(struct pakfire* pakfire, struct pakfire_file // Write the header r = archive_write_header(data->archive, entry); if (r) { - ERROR(pakfire, "Error writing file header: %s\n", + CTX_ERROR(data->ctx, "Error writing file header: %s\n", archive_error_string(data->archive)); goto ERROR; } @@ -951,7 +951,7 @@ static int __pakfire_compress_entry(struct pakfire* pakfire, struct pakfire_file } // Copy the payload into the archive - r = pakfire_copy_data_from_file(pakfire, data->archive, f); + r = pakfire_copy_data_from_file(data->ctx, data->archive, f); if (r) goto ERROR; } @@ -1049,6 +1049,7 @@ int pakfire_compress(struct pakfire* pakfire, struct archive* archive, struct pakfire_ctx* ctx = pakfire_ctx(pakfire); struct pakfire_compress data = { + .ctx = ctx, .pakfire = pakfire, .archive = archive, .filelist = filelist, @@ -1085,7 +1086,7 @@ int pakfire_compress(struct pakfire* pakfire, struct archive* archive, // Setup the link resolver data.linkresolver = archive_entry_linkresolver_new(); if (!data.linkresolver) { - ERROR(pakfire, "Could not setup link resolver: m\n"); + CTX_ERROR(ctx, "Could not setup link resolver: m\n"); goto ERROR; } @@ -1118,10 +1119,12 @@ int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** ar char value[16]; int r; + struct pakfire_ctx* ctx = pakfire_ctx(pakfire); + // Open a new archive a = archive_write_new(); if (!a) { - ERROR(pakfire, "archive_write_new() failed\n"); + CTX_ERROR(ctx, "archive_write_new() failed\n"); r = 1; goto ERROR; } @@ -1129,14 +1132,14 @@ int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** ar // Use the PAX format r = archive_write_set_format_pax(a); if (r) { - ERROR(pakfire, "Could not set format to PAX: %s\n", archive_error_string(a)); + CTX_ERROR(ctx, "Could not set format to PAX: %s\n", archive_error_string(a)); goto ERROR; } // Store any extended attributes in the SCHILY headers r = archive_write_set_format_option(a, "pax", "xattrheader", "SCHILY"); if (r) { - ERROR(pakfire, "Could not set xattrheader option: %s\n", archive_error_string(a)); + CTX_ERROR(ctx, "Could not set xattrheader option: %s\n", archive_error_string(a)); goto ERROR; } @@ -1145,7 +1148,7 @@ int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** ar // Enable Zstd r = archive_write_add_filter_zstd(a); if (r) { - ERROR(pakfire, "Could not enable Zstandard compression: %s\n", + CTX_ERROR(ctx, "Could not enable Zstandard compression: %s\n", archive_error_string(a)); goto ERROR; } @@ -1161,7 +1164,7 @@ int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** ar r = archive_write_set_filter_option(a, NULL, "compression-level", value); if (r) { - ERROR(pakfire, "Could not set Zstandard compression level: %s\n", + CTX_ERROR(ctx, "Could not set Zstandard compression level: %s\n", archive_error_string(a)); goto ERROR; } @@ -1174,14 +1177,14 @@ int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** ar if (processors > 1) { r = pakfire_string_format(value, "%ld", processors); if (r) { - ERROR(pakfire, "Could not format threads: %m\n"); + CTX_ERROR(ctx, "Could not format threads: %m\n"); goto ERROR; } // Try using multiple threads r = archive_write_set_filter_option(a, NULL, "threads", value); if (r) { - ERROR(pakfire, "Could not enable %ld threads for compression: %s\n", + CTX_ERROR(ctx, "Could not enable %ld threads for compression: %s\n", processors, archive_error_string(a)); goto ERROR; } @@ -1193,7 +1196,7 @@ int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** ar if (f) { r = archive_write_open_FILE(a, f); if (r) { - ERROR(pakfire, "archive_write_open_FILE() failed: %s\n", archive_error_string(a)); + CTX_ERROR(ctx, "archive_write_open_FILE() failed: %s\n", archive_error_string(a)); goto ERROR; } } @@ -1201,11 +1204,17 @@ int pakfire_compress_create_archive(struct pakfire* pakfire, struct archive** ar // Success *archive = a; + if (ctx) + pakfire_ctx_unref(ctx); + return 0; ERROR: if (a) archive_write_free(a); + if (ctx) + pakfire_ctx_unref(ctx); + return r; }