aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm56
1 files changed, 31 insertions, 25 deletions
diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm
index fc29f1d..e47d660 100644
--- a/guix-build-coordinator/agent-messaging/http.scm
+++ b/guix-build-coordinator/agent-messaging/http.scm
@@ -300,31 +300,37 @@
(log 'INFO "finished compressing " file ", now sending")
(retry-on-error
(lambda ()
- (call-with-input-file template
- (lambda (file-port)
- (let ((bytes (get-partial-upload-bytes)))
- (when bytes
- (seek file-port bytes SEEK_SET)
- (log 'INFO "resuming upload from byte " bytes))
-
- (let-values (((response body)
- (call-with-streaming-http-request
- (uri #:resume? (integer? bytes))
- (lambda (port)
- (with-time-logging
- (simple-format #f "sending ~A" file)
- (dump-port file-port port
- #:buffer-size 65536)))
- #:headers `((Authorization . ,auth-value))
- #:method (if bytes 'POST 'PUT))))
- (when (>= (response-code response) 400)
- (raise-exception
- (make-exception-with-message
- (coordinator-handle-failed-request log
- 'PUT
- (uri-path uri)
- response
- body)))))))))
+ (let ((bytes (get-partial-upload-bytes)))
+ ;; Check if the server has all the bytes
+ (unless (and bytes
+ (eq? bytes (stat:size (stat template))))
+
+ ;; Still more to send
+ (call-with-input-file template
+ (lambda (file-port)
+ (when bytes
+ (seek file-port bytes SEEK_SET)
+ (log 'INFO "resuming upload from byte " bytes))
+
+ (let-values (((response body)
+ (call-with-streaming-http-request
+ (uri #:resume? (integer? bytes))
+ (lambda (port)
+ (with-time-logging
+ (simple-format #f "sending ~A" file)
+ (dump-port file-port port
+ #:buffer-size 65536)))
+ #:headers `((Authorization . ,auth-value))
+ #:method (if bytes 'POST 'PUT)
+ #:report-bytes-sent report-bytes-sent)))
+ (when (>= (response-code response) 400)
+ (raise-exception
+ (make-exception-with-message
+ (coordinator-handle-failed-request log
+ 'PUT
+ (uri-path uri)
+ response
+ body))))))))))
#:times 100
#:delay (random 15))