aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-10-10 14:56:08 +0100
committerChristopher Baines <mail@cbaines.net>2020-10-10 14:56:08 +0100
commite339d1a6a391c3bea06a0127ff5914b94d6316b0 (patch)
tree65df0fd854138a42c09367329fde14f1a1072bed
parente701d4d7f24a11d94cf504e7efbcee4e1091b092 (diff)
downloadbuild-coordinator-e339d1a6a391c3bea06a0127ff5914b94d6316b0.tar
build-coordinator-e339d1a6a391c3bea06a0127ff5914b94d6316b0.tar.gz
Guard against receiving parts of build log files
-rw-r--r--guix-build-coordinator/agent-messaging/http/server.scm12
1 files 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