aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-05-01 17:24:41 +0200
committerLudovic Courtès <ludo@gnu.org>2017-05-01 17:28:20 +0200
commitdff3189c7d5d95177ff592789e1bcb73a4adcc9e (patch)
tree897cb0f23c7b51a248ac9284883fafec81ed0dfa /guix
parente93793059d4a15894e407525bdc33fd06e2b104a (diff)
downloadgnu-guix-dff3189c7d5d95177ff592789e1bcb73a4adcc9e.tar
gnu-guix-dff3189c7d5d95177ff592789e1bcb73a4adcc9e.tar.gz
publish: Produce a "FileSize" narinfo field when possible.
* guix/scripts/publish.scm (narinfo-string): Add #:file-size parameter. Produce a "FileSize" field when COMPRESSION is eq? to '%no-compression' or when FILE-SIZE is true. (bake-narinfo+nar): Pass #:file-size. * tests/publish.scm ("/*.narinfo") ("/*.narinfo with properly encoded '+' sign") ("with cache"): Check for "FileSize".
Diffstat (limited to 'guix')
-rw-r--r--guix/scripts/publish.scm18
1 files changed, 13 insertions, 5 deletions
diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index 3faff061a7..a589f149d3 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -240,10 +240,12 @@ compression disabled~%"))
(define* (narinfo-string store store-path key
#:key (compression %no-compression)
- (nar-path "nar"))
+ (nar-path "nar") file-size)
"Generate a narinfo key/value string for STORE-PATH; an exception is raised
if STORE-PATH is invalid. Produce a URL that corresponds to COMPRESSION. The
-narinfo is signed with KEY. NAR-PATH specifies the prefix for nar URLs."
+narinfo is signed with KEY. NAR-PATH specifies the prefix for nar URLs.
+Optionally, FILE-SIZE can specify the size in bytes of the compressed NAR; it
+informs the client of how much needs to be downloaded."
(let* ((path-info (query-path-info store store-path))
(compression (actual-compression store-path compression))
(url (encode-and-join-uri-path
@@ -257,6 +259,8 @@ narinfo is signed with KEY. NAR-PATH specifies the prefix for nar URLs."
(hash (bytevector->nix-base32-string
(path-info-hash path-info)))
(size (path-info-nar-size path-info))
+ (file-size (or file-size
+ (and (eq? compression %no-compression) size)))
(references (string-join
(map basename (path-info-references path-info))
" "))
@@ -268,10 +272,13 @@ URL: ~a
Compression: ~a
NarHash: sha256:~a
NarSize: ~d
-References: ~a~%"
+References: ~a~%~a"
store-path url
(compression-type compression)
- hash size references))
+ hash size references
+ (if file-size
+ (format #f "FileSize: ~a~%" file-size)
+ "")))
;; Do not render a "Deriver" or "System" line if we are rendering
;; info for a derivation.
(info (if (not deriver)
@@ -465,7 +472,8 @@ requested using POOL."
(display (narinfo-string store item
(%private-key)
#:nar-path nar-path
- #:compression compression)
+ #:compression compression
+ #:file-size (stat:size (stat nar)))
port))))))
;; XXX: Declare the 'Guix-Compression' HTTP header, which is in fact for