From e91a97c44dc824128e45e4a7a80ab9c95fa15c4c Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 13 May 2020 23:07:28 +0100 Subject: Guard against failed file uploads Only move the file in to the destination location when the upload completes. --- guix-build-coordinator/agent-messaging/http.scm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm index 40d6653..61405b6 100644 --- a/guix-build-coordinator/agent-messaging/http.scm +++ b/guix-build-coordinator/agent-messaging/http.scm @@ -337,13 +337,17 @@ 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-output-file-location datastore uuid output-name))) + (let* ((output-file-name + (build-output-file-location datastore uuid output-name)) + (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 ((start-time (current-time time-utc))) (let loop ((bv (get-bytevector-some body)) @@ -384,6 +388,8 @@ port. Also, the port used can be changed by passing the --port option.\n" 0.1))) bytes-read) last-progress-update-bytes-read)))))))) + (rename-file tmp-output-file-name + output-file-name) #t)) (no-content) (render-json -- cgit v1.2.3