aboutsummaryrefslogtreecommitdiff
path: root/guix/scripts/substitute.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2023-06-08 22:43:05 +0200
committerLudovic Courtès <ludo@gnu.org>2023-06-08 22:54:58 +0200
commit885d524f79aa4bbfac5dfebf285e1e248184ee70 (patch)
treee48cdf6f498d2c95fad985d58436d4fb19f3e532 /guix/scripts/substitute.scm
parent3f5e14182931f123c10513a3e1e2abaebfb52279 (diff)
downloadguix-885d524f79aa4bbfac5dfebf285e1e248184ee70.tar
guix-885d524f79aa4bbfac5dfebf285e1e248184ee70.tar.gz
substitute: Gracefully retry after failed partial downloads.
Fixes <https://issues.guix.gnu.org/63443>. Reported by Attila Lendvai <attila@lendvai.name>. * guix/scripts/substitute.scm (catch-system-error): New macro. (download-nar): Add call to 'delete-file-recursively'. * tests/substitute.scm ("substitute, previous partial download around"): New test.
Diffstat (limited to 'guix/scripts/substitute.scm')
-rwxr-xr-xguix/scripts/substitute.scm11
1 files changed, 10 insertions, 1 deletions
diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm
index de7b77b0bf..8b1f7d6fda 100755
--- a/guix/scripts/substitute.scm
+++ b/guix/scripts/substitute.scm
@@ -38,7 +38,7 @@
#:use-module (guix cache)
#:use-module (gcrypt pk-crypto)
#:use-module (guix pki)
- #:use-module ((guix build utils) #:select (mkdir-p))
+ #:autoload (guix build utils) (mkdir-p delete-file-recursively)
#:use-module ((guix build download)
#:select (uri-abbreviation nar-uri-abbreviation
(open-connection-for-uri
@@ -445,6 +445,11 @@ server certificates."
"Bind PORT with EXP... to a socket connected to URI."
(call-with-cached-connection uri (lambda (port) exp ...)))
+(define-syntax-rule (catch-system-error exp)
+ (catch 'system-error
+ (lambda () exp)
+ (const #f)))
+
(define* (download-nar narinfo destination
#:key status-port
deduplicate? print-build-trace?)
@@ -503,6 +508,10 @@ STATUS-PORT."
(narinfo-path narinfo)
(narinfo-uri-base narinfo)))))
+ ;; Delete DESTINATION first--necessary when starting over after a failed
+ ;; download.
+ (catch-system-error (delete-file-recursively destination))
+
(let ((choices (narinfo-preferred-uris narinfo
#:fast-decompression?
%prefer-fast-decompression?)))