]> git.ipfire.org Git - pakfire.git/commitdiff
log file: Add a human readable filename argument
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Jan 2025 17:10:02 +0000 (17:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Jan 2025 17:10:02 +0000 (17:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/job.c
src/pakfire/log_file.c
src/pakfire/log_file.h
tests/libpakfire/log_file.c

index dffdcba43251ff33c5bc8b7d5114734870a74b2c..620b32f948349c593195b6e09ba29dad3e2c290f 100644 (file)
@@ -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;
index 50fadfe9afc15c2f24468502a45afde262cda21a..ca75eef7254984b59aec09fc898721aa3fa393a8 100644 (file)
@@ -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;
 }
index 6e9b3cf9608e92fc7e617bb772c83d0005953cec..2f60aa343c830d7313c8ca3b983f39534512ea94 100644 (file)
@@ -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);
index 3c22ea7c599e2fb2b5a1d860a9f5e52f01e1b197..aeb37a5c3f080f15b177d8befb9b6a2586554115 100644 (file)
@@ -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)));