From e339d1a6a391c3bea06a0127ff5914b94d6316b0 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 10 Oct 2020 14:56:08 +0100 Subject: Guard against receiving parts of build log files --- guix-build-coordinator/agent-messaging/http/server.scm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/guix-build-coordinator/agent-messaging/http/server.scm b/guix-build-coordinator/agent-messaging/http/server.scm index 0b2f963..7656c6f 100644 --- a/guix-build-coordinator/agent-messaging/http/server.scm +++ b/guix-build-coordinator/agent-messaging/http/server.scm @@ -337,18 +337,24 @@ port. Also, the port used can be changed by passing the --port option.\n" (let ((agent-id-for-build (datastore-agent-for-build datastore uuid))) (if (authenticated? agent-id-for-build request) - (let ((output-file-name - (build-log-file-location datastore uuid format))) + (let* ((output-file-name + (build-log-file-location datastore uuid format)) + (tmp-output-file-name + (string-append output-file-name ".tmp"))) (mkdir-p (dirname output-file-name)) + (when (file-exists? tmp-output-file-name) + (delete-file tmp-output-file-name)) (if (call-with-worker-thread chunked-request-channel (lambda () - (call-with-output-file output-file-name + (call-with-output-file tmp-output-file-name (lambda (output-port) (let loop ((bv (get-bytevector-some body))) (unless (eof-object? bv) (put-bytevector output-port bv) (loop (get-bytevector-some body)))))) + (rename-file tmp-output-file-name + output-file-name) #t)) (no-content) (render-json -- cgit v1.2.3