summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2022-09-22 12:08:16 +0200
committerLudovic Courtès <ludo@gnu.org>2022-09-28 22:28:24 +0200
commitf75592533e1921f4b3614a0de345f5c037b90cd6 (patch)
treea8d2df4062da70ed302390bcc22cab8757ad7b7a
parentafcc6d636f7d7b1914fa3425da3574db4a94f26f (diff)
downloadguix-f75592533e1921f4b3614a0de345f5c037b90cd6.tar.gz
substitute: Split nar download.
* guix/scripts/substitute.scm (download-nar): New procedure, with most
of the code moved from...
(process-substitution): ... here.  Call it.
-rwxr-xr-xguix/scripts/substitute.scm52
1 files changed, 32 insertions, 20 deletions
diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm
index cdf591ac4d..e3b382d0d8 100755
--- a/guix/scripts/substitute.scm
+++ b/guix/scripts/substitute.scm
@@ -437,20 +437,13 @@ server certificates."
   "Bind PORT with EXP... to a socket connected to URI."
   (call-with-cached-connection uri (lambda (port) exp ...)))
 
-(define* (process-substitution port store-item destination
-                               #:key cache-urls acl
-                               deduplicate? print-build-trace?)
-  "Substitute STORE-ITEM (a store file name) from CACHE-URLS, and write it to
-DESTINATION as a nar file.  Verify the substitute against ACL, and verify its
-hash against what appears in the narinfo.  When DEDUPLICATE? is true, and if
-DESTINATION is in the store, deduplicate its files.  Print a status line to
-PORT."
-  (define narinfo
-    (lookup-narinfo cache-urls store-item
-                    (if (%allow-unauthenticated-substitutes?)
-                        (const #t)
-                        (cut valid-narinfo? <> acl))))
-
+(define* (download-nar narinfo destination
+                       #:key status-port
+                       deduplicate? print-build-trace?)
+  "Download the nar prescribed in NARINFO, which is assumed to be authentic
+and authorized, and write it to DESTINATION.  When DEDUPLICATE? is true, and
+if DESTINATION is in the store, deduplicate its files.  Print a status line to
+STATUS-PORT."
   (define destination-in-store?
     (string-prefix? (string-append (%store-prefix) "/")
                     destination))
@@ -490,10 +483,6 @@ PORT."
        (leave (G_ "unsupported substitute URI scheme: ~a~%")
               (uri->string uri)))))
 
-  (unless narinfo
-    (leave (G_ "no valid substitute for '~a'~%")
-           store-item))
-
   (let ((uri compression file-size
              (narinfo-best-uri narinfo
                                #:fast-decompression?
@@ -575,14 +564,37 @@ PORT."
       (let ((actual (get-hash)))
         (if (bytevector=? actual expected)
             ;; Tell the daemon that we're done.
-            (format port "success ~a ~a~%"
+            (format status-port "success ~a ~a~%"
                     (narinfo-hash narinfo) (narinfo-size narinfo))
             ;; The actual data has a different hash than that in NARINFO.
-            (format port "hash-mismatch ~a ~a ~a~%"
+            (format status-port "hash-mismatch ~a ~a ~a~%"
                     (hash-algorithm-name algorithm)
                     (bytevector->nix-base32-string expected)
                     (bytevector->nix-base32-string actual)))))))
 
+(define* (process-substitution port store-item destination
+                               #:key cache-urls acl
+                               deduplicate? print-build-trace?)
+  "Substitute STORE-ITEM (a store file name) from CACHE-URLS, and write it to
+DESTINATION as a nar file.  Verify the substitute against ACL, and verify its
+hash against what appears in the narinfo.  When DEDUPLICATE? is true, and if
+DESTINATION is in the store, deduplicate its files.  Print a status line to
+PORT."
+  (define narinfo
+    (lookup-narinfo cache-urls store-item
+                    (if (%allow-unauthenticated-substitutes?)
+                        (const #t)
+                        (cut valid-narinfo? <> acl))))
+
+  (unless narinfo
+    (leave (G_ "no valid substitute for '~a'~%")
+           store-item))
+
+  (download-nar narinfo destination
+                #:status-port port
+                #:deduplicate? deduplicate?
+                #:print-build-trace? print-build-trace?))
+
 
 ;;;
 ;;; Entry point.