summaryrefslogtreecommitdiff
path: root/guix/swh.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2024-01-25 23:27:51 +0100
committerLudovic Courtès <ludo@gnu.org>2024-02-12 12:03:53 +0100
commit1b72e1430794fd09bb2be1d72f482a40c0f9196e (patch)
treebb70db365040ba86f70d7ba69043f57f1f381c70 /guix/swh.scm
parentbe773bd192466fa7e26938a157c0885adf46139e (diff)
swh: Add ‘swh-download-directory-by-nar-hash’.
This allows us to take advantage of content addressing by giving SWH the expected nar hash. * guix/swh.scm (swh-download-directory-by-nar-hash): New procedure. Change-Id: I0494ee15a3cde390a22552de7c2246e0314ba7b5
Diffstat (limited to 'guix/swh.scm')
-rw-r--r--guix/swh.scm24
1 files changed, 24 insertions, 0 deletions
diff --git a/guix/swh.scm b/guix/swh.scm
index 60e97c6d38..be1eb7d151 100644
--- a/guix/swh.scm
+++ b/guix/swh.scm
@@ -123,6 +123,7 @@
commit-id?
swh-download-directory
+ swh-download-directory-by-nar-hash
swh-download))
;;; Commentary:
@@ -805,3 +806,26 @@ wait until it becomes available, which could take several minutes."
"SWH: revision ~s originating from ~a could not be found~%"
reference url)
#f)))
+
+(define* (swh-download-directory-by-nar-hash hash algorithm output
+ #:key
+ (log-port (current-error-port)))
+ "Download from Software Heritage the directory with the given nar HASH for
+ALGORITHM (a symbol such as 'sha256), and unpack it in OUTPUT. Return #t on
+success and #f on failure.
+
+This procedure uses the \"vault\", which contains \"cooked\" directories in
+the form of tarballs. If the requested directory is not cooked yet, it will
+wait until it becomes available, which could take several minutes."
+ (match (lookup-directory-by-nar-hash hash algorithm)
+ (#f
+ (format log-port
+ "SWH: directory with nar-~a hash ~a not found~%"
+ algorithm (bytevector->base16-string hash))
+ #f)
+ (swhid
+ (format log-port "SWH: found directory with nar-~a hash ~a at '~a'~%"
+ algorithm (bytevector->base16-string hash) swhid)
+ (swh-download-archive swhid output
+ #:archive-type 'flat ;SWHID denotes a directory
+ #:log-port log-port))))