aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/agent-messaging
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-05-13 23:07:28 +0100
committerChristopher Baines <mail@cbaines.net>2020-05-13 23:07:28 +0100
commite91a97c44dc824128e45e4a7a80ab9c95fa15c4c (patch)
treeed5c9d3dd9f8157c51afa8965420e2e66e0e40a1 /guix-build-coordinator/agent-messaging
parent53df9c2591d94d52f96599285c2b37cd96c4e6b3 (diff)
downloadbuild-coordinator-e91a97c44dc824128e45e4a7a80ab9c95fa15c4c.tar
build-coordinator-e91a97c44dc824128e45e4a7a80ab9c95fa15c4c.tar.gz
Guard against failed file uploads
Only move the file in to the destination location when the upload completes.
Diffstat (limited to 'guix-build-coordinator/agent-messaging')
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm12
1 files 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