#include <lzma.h>
#include <zstd.h>
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
#include <pakfire/ctx.h>
#include <pakfire/compress.h>
#include <pakfire/file.h>
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;
}
// Common compression
struct pakfire_compress {
+ // Reference to context
+ struct pakfire_ctx* ctx;
+
// Reference to Pakfire
struct pakfire* pakfire;
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];
// 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;
}
}
// 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;
}
}
// 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;
}
struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
struct pakfire_compress data = {
+ .ctx = ctx,
.pakfire = pakfire,
.archive = archive,
.filelist = filelist,
// 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;
}
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;
}
// 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;
}
// 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;
}
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;
}
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;
}
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;
}
}
// 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;
}