From: Michael Tremer Date: Thu, 26 Jun 2025 14:50:01 +0000 (+0000) Subject: job: Upload the log file when a build has finished X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cbab867f4b2a50e9425620922be29244f99b251a;p=pakfire.git job: Upload the log file when a build has finished Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/job.c b/src/pakfire/job.c index 6d98542c..8fc6ad07 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -304,18 +304,49 @@ ERROR: return r; } +static int pakfire_job_upload_packages(struct pakfire_job* self) { + return 0; // XXX TODO +} + +/* + Called when the log file has been uploaded... +*/ +static int pakfire_job_logfile_uploaded(struct pakfire_client* client, + pakfire_client_upload_status status, const char* path, const char* uuid, void* data) { + struct pakfire_job* self = data; + + // Check the status + switch (status) { + case PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL: + // Free any previous upload IDs + if (self->uploads.logfile) + free(self->uploads.logfile); + + // Store the UUID of the upload + self->uploads.logfile = strdup(uuid); + if (self->uploads.logfile) + ERROR(self->ctx, "Failed to store the log file UUID: %m\n"); + break; + + // Log an error if we could not upload the log file + default: + ERROR(self->ctx, "Failed to upload the log file: %s\n", strerror(status)); + break; + } + + // Continue with uploading the packages + return pakfire_job_upload_packages(self); +} + /* Called when the job has finished with status as the error code. */ -static int pakfire_job_finished(struct pakfire_job* job, int status) { +static int pakfire_job_finished(struct pakfire_job* job, const siginfo_t* si) { struct pakfire_xfer* xfer = NULL; const char* filename = NULL; const char* path = NULL; - char* logfile = NULL; int r; - DEBUG(job->ctx, "Job %s has finished with status %d\n", job->id, status); - // Close the log file r = pakfire_log_file_close(job->log.file); if (r < 0) { @@ -339,15 +370,14 @@ static int pakfire_job_finished(struct pakfire_job* job, int status) { goto ERROR; } -#if 0 // Upload the log file - r = pakfire_client_upload(job->client, path, filename, &logfile); + r = pakfire_client_upload(job->client, path, filename, pakfire_job_logfile_uploaded, job); if (r < 0) { ERROR(job->ctx, "Could not upload the log file: %s\n", strerror(-r)); goto ERROR; } -#endif +#if 0 // Create a new xfer r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s/finished", job->id); if (r < 0) @@ -383,6 +413,7 @@ static int pakfire_job_finished(struct pakfire_job* job, int status) { r = pakfire_xfer_run_api_request(xfer, NULL, NULL); if (r < 0) goto ERROR; +#endif // Let the builder know this is finished r = pakfire_builder_job_finished(job->builder, job); @@ -475,7 +506,7 @@ static int pakfire_job_exited(sd_event_source* s, const siginfo_t* si, void* dat } // Signal that the job has finished - return pakfire_job_finished(job, si->si_status); + return pakfire_job_finished(job, si); } static int pakfire_job_send_log(struct pakfire_job* job, int priority, const char* line, size_t length) {