summary refs log tree commit diff
path: root/maintainers
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2011-10-30 00:00:20 +0000
committerLudovic Courtès <ludo@gnu.org>2011-10-30 00:00:20 +0000
commit573c9178b551ffb417222730e614aea99e67f999 (patch)
treec162a72df9d69d606e8b6cfee121c13d1e40af29 /maintainers
parent354b1a12c1f588cdfa2f35896ada4c9ba20e3a28 (diff)
downloadnixpkgs-573c9178b551ffb417222730e614aea99e67f999.tar
nixpkgs-573c9178b551ffb417222730e614aea99e67f999.tar.gz
nixpkgs-573c9178b551ffb417222730e614aea99e67f999.tar.bz2
nixpkgs-573c9178b551ffb417222730e614aea99e67f999.tar.lz
nixpkgs-573c9178b551ffb417222730e614aea99e67f999.tar.xz
nixpkgs-573c9178b551ffb417222730e614aea99e67f999.tar.zst
nixpkgs-573c9178b551ffb417222730e614aea99e67f999.zip
gnupdate: Make `nix-prefetch-url' memoizing.
* maintainers/scripts/gnu/gnupdate (memoize): New procedure.
  (nix-prefetch-url): Use it.

svn path=/nixpkgs/trunk/; revision=30109
Diffstat (limited to 'maintainers')
-rwxr-xr-xmaintainers/scripts/gnu/gnupdate46
1 files changed, 31 insertions, 15 deletions
diff --git a/maintainers/scripts/gnu/gnupdate b/maintainers/scripts/gnu/gnupdate
index c33fc00e7ae..eabe3e581d8 100755
--- a/maintainers/scripts/gnu/gnupdate
+++ b/maintainers/scripts/gnu/gnupdate
@@ -328,21 +328,36 @@ replaced by the result of their application to DERIVATIONS, a vhash."
         status
         #f)))
 
-(define (nix-prefetch-url url)
-  ;; Download URL in the Nix store and return the base32-encoded SHA256 hash
-  ;; of the file at URL
-  (let* ((pipe (open-pipe* OPEN_READ "nix-prefetch-url" url))
-         (hash (read-line pipe)))
-    (if (or (pipe-failed? pipe)
-            (eof-object? hash))
-        (values #f #f)
-        (let* ((pipe (open-pipe* OPEN_READ "nix-store" "--print-fixed-path"
-                                   "sha256" hash (basename url)))
-               (path (read-line pipe)))
-          (if (or (pipe-failed? pipe)
-                  (eof-object? path))
-              (values #f #f)
-              (values (string-trim-both hash) (string-trim-both path)))))))
+(define (memoize proc)
+  "Return a memoizing version of PROC."
+  (let ((cache (make-hash-table)))
+    (lambda args
+      (let ((results (hash-ref cache args)))
+        (if results
+            (apply values results)
+            (let ((results (call-with-values (lambda ()
+                                               (apply proc args))
+                             list)))
+              (hash-set! cache args results)
+              (apply values results)))))))
+
+(define nix-prefetch-url
+  (memoize
+   (lambda (url)
+     "Download URL in the Nix store and return the base32-encoded SHA256 hash of
+the file at URL."
+     (let* ((pipe (open-pipe* OPEN_READ "nix-prefetch-url" url))
+            (hash (read-line pipe)))
+       (if (or (pipe-failed? pipe)
+               (eof-object? hash))
+           (values #f #f)
+           (let* ((pipe (open-pipe* OPEN_READ "nix-store" "--print-fixed-path"
+                                    "sha256" hash (basename url)))
+                  (path (read-line pipe)))
+             (if (or (pipe-failed? pipe)
+                     (eof-object? path))
+                 (values #f #f)
+                 (values (string-trim-both hash) (string-trim-both path)))))))))
 
 (define (update-nix-expression file
                                old-version old-hash
@@ -926,6 +941,7 @@ pairs.  Example: (\"mit-scheme-9.0.1\" . \"/gnu/mit-scheme/stable.pkg/9.0.1\").
         gnu-packages))
 
 (define (fetch-gnu project directory version archive-type)
+  "Download PROJECT's tarball over FTP."
   (let* ((server  (ftp-server/directory project))
          (base    (string-append project "-" version ".tar." archive-type))
          (url     (string-append "ftp://" server "/" directory "/" base))