From: Michael Tremer Date: Wed, 29 Jan 2025 17:10:02 +0000 (+0000) Subject: log file: Add a human readable filename argument X-Git-Tag: 0.9.30~294 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=34fecc52156f5d463891cbd0a0859b9302072eaa;p=pakfire.git log file: Add a human readable filename argument Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/job.c b/src/pakfire/job.c index dffdcba4..620b32f9 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -305,6 +305,7 @@ ERROR: static int pakfire_job_finished(struct pakfire_job* job, int status) { struct pakfire_xfer* xfer = NULL; char job_id[UUID_STR_LEN]; + const char* filename = NULL; const char* path = NULL; char* logfile = NULL; int r; @@ -323,6 +324,14 @@ static int pakfire_job_finished(struct pakfire_job* job, int status) { } } + // Fetch the filename of the log file + filename = pakfire_log_file_filename(job->log.file); + if (!filename) { + ERROR(job->ctx, "Log file has no filename\n"); + r = -EINVAL; + goto ERROR; + } + // Fetch the path of the log file path = pakfire_log_file_path(job->log.file); if (!path) { @@ -332,7 +341,7 @@ static int pakfire_job_finished(struct pakfire_job* job, int status) { } // Upload the log file - r = pakfire_buildservice_upload(job->service, path, NULL, &logfile); + r = pakfire_buildservice_upload(job->service, path, filename, &logfile); if (r < 0) { ERROR(job->ctx, "Could not upload the log file: %s\n", strerror(-r)); goto ERROR; @@ -663,7 +672,7 @@ static int pakfire_job_child(struct pakfire_job* job) { pakfire_ctx_set_log_callback(ctx, pakfire_job_log, job); // Open a new log file - r = pakfire_log_file_create(&job->log.file, ctx, PAKFIRE_LOG_FILE_COMPRESS); + r = pakfire_log_file_create(&job->log.file, ctx, job_id, PAKFIRE_LOG_FILE_COMPRESS); if (r < 0) { ERROR(ctx, "Could not open log file: %s\n", strerror(-r)); goto ERROR; diff --git a/src/pakfire/log_file.c b/src/pakfire/log_file.c index 50fadfe9..ca75eef7 100644 --- a/src/pakfire/log_file.c +++ b/src/pakfire/log_file.c @@ -31,6 +31,9 @@ struct pakfire_log_file { struct pakfire_ctx* ctx; int nrefs; + // Filename + char filename[PATH_MAX]; + // Flags int flags; @@ -53,7 +56,8 @@ static void pakfire_log_file_free(struct pakfire_log_file* self) { free(self); } -int pakfire_log_file_create(struct pakfire_log_file** file, struct pakfire_ctx* ctx, int flags) { +int pakfire_log_file_create(struct pakfire_log_file** file, struct pakfire_ctx* ctx, + const char* filename, int flags) { struct pakfire_log_file* self = NULL; int r; @@ -71,6 +75,11 @@ int pakfire_log_file_create(struct pakfire_log_file** file, struct pakfire_ctx* // Store flags self->flags = flags; + // Store the filename + r = pakfire_string_set(self->filename, filename); + if (r < 0) + goto ERROR; + // Make some path r = pakfire_string_set(self->path, PAKFIRE_TMP_DIR "/pakfire-log.XXXXXX"); if (r < 0) @@ -91,9 +100,14 @@ int pakfire_log_file_create(struct pakfire_log_file** file, struct pakfire_ctx* r = -errno; goto ERROR; } + + // Add a suffix to the filename + r = pakfire_string_append(self->filename, ".zst"); + if (r < 0) + goto ERROR; } - DEBUG(self->ctx, "Created log file %s\n", self->path); + DEBUG(self->ctx, "Created log file %s (%s)\n", self->filename, self->path); // Return the pointer *file = self; @@ -119,6 +133,10 @@ struct pakfire_log_file* pakfire_log_file_unref(struct pakfire_log_file* self) { return NULL; } +const char* pakfire_log_file_filename(struct pakfire_log_file* self) { + return self->filename; +} + const char* pakfire_log_file_path(struct pakfire_log_file* self) { return self->path; } diff --git a/src/pakfire/log_file.h b/src/pakfire/log_file.h index 6e9b3cf9..2f60aa34 100644 --- a/src/pakfire/log_file.h +++ b/src/pakfire/log_file.h @@ -34,10 +34,11 @@ enum pakfire_log_file_flags { }; int pakfire_log_file_create(struct pakfire_log_file** file, - struct pakfire_ctx* ctx, int flags); + struct pakfire_ctx* ctx, const char* filename, int flags); struct pakfire_log_file* pakfire_log_file_ref(struct pakfire_log_file* self); struct pakfire_log_file* pakfire_log_file_unref(struct pakfire_log_file* self); +const char* pakfire_log_file_filename(struct pakfire_log_file* self); const char* pakfire_log_file_path(struct pakfire_log_file* self); int pakfire_log_file_close(struct pakfire_log_file* self); diff --git a/tests/libpakfire/log_file.c b/tests/libpakfire/log_file.c index 3c22ea7c..aeb37a5c 100644 --- a/tests/libpakfire/log_file.c +++ b/tests/libpakfire/log_file.c @@ -31,7 +31,7 @@ static int __test_simple(const struct test* t, int flags) { int r = EXIT_FAILURE; // Create a new log file - ASSERT_SUCCESS(pakfire_log_file_create(&file, t->ctx, flags)); + ASSERT_SUCCESS(pakfire_log_file_create(&file, t->ctx, "test.log", flags)); // Store a copy of the path ASSERT_SUCCESS(pakfire_string_set(path, pakfire_log_file_path(file)));