mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-26 20:49:29 -05:00
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".
This commit is contained in:
parent
e93793059d
commit
dff3189c7d
2 changed files with 30 additions and 13 deletions
|
@ -240,10 +240,12 @@ (define base64-encode-string
|
||||||
|
|
||||||
(define* (narinfo-string store store-path key
|
(define* (narinfo-string store store-path key
|
||||||
#:key (compression %no-compression)
|
#: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
|
"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
|
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))
|
(let* ((path-info (query-path-info store store-path))
|
||||||
(compression (actual-compression store-path compression))
|
(compression (actual-compression store-path compression))
|
||||||
(url (encode-and-join-uri-path
|
(url (encode-and-join-uri-path
|
||||||
|
@ -257,6 +259,8 @@ (define* (narinfo-string store store-path key
|
||||||
(hash (bytevector->nix-base32-string
|
(hash (bytevector->nix-base32-string
|
||||||
(path-info-hash path-info)))
|
(path-info-hash path-info)))
|
||||||
(size (path-info-nar-size path-info))
|
(size (path-info-nar-size path-info))
|
||||||
|
(file-size (or file-size
|
||||||
|
(and (eq? compression %no-compression) size)))
|
||||||
(references (string-join
|
(references (string-join
|
||||||
(map basename (path-info-references path-info))
|
(map basename (path-info-references path-info))
|
||||||
" "))
|
" "))
|
||||||
|
@ -268,10 +272,13 @@ (define* (narinfo-string store store-path key
|
||||||
Compression: ~a
|
Compression: ~a
|
||||||
NarHash: sha256:~a
|
NarHash: sha256:~a
|
||||||
NarSize: ~d
|
NarSize: ~d
|
||||||
References: ~a~%"
|
References: ~a~%~a"
|
||||||
store-path url
|
store-path url
|
||||||
(compression-type compression)
|
(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
|
;; Do not render a "Deriver" or "System" line if we are rendering
|
||||||
;; info for a derivation.
|
;; info for a derivation.
|
||||||
(info (if (not deriver)
|
(info (if (not deriver)
|
||||||
|
@ -465,7 +472,8 @@ (define* (bake-narinfo+nar cache item
|
||||||
(display (narinfo-string store item
|
(display (narinfo-string store item
|
||||||
(%private-key)
|
(%private-key)
|
||||||
#:nar-path nar-path
|
#:nar-path nar-path
|
||||||
#:compression compression)
|
#:compression compression
|
||||||
|
#:file-size (stat:size (stat nar)))
|
||||||
port))))))
|
port))))))
|
||||||
|
|
||||||
;; XXX: Declare the 'Guix-Compression' HTTP header, which is in fact for
|
;; XXX: Declare the 'Guix-Compression' HTTP header, which is in fact for
|
||||||
|
|
|
@ -122,13 +122,15 @@ (define (wait-until-ready port)
|
||||||
Compression: none
|
Compression: none
|
||||||
NarHash: sha256:~a
|
NarHash: sha256:~a
|
||||||
NarSize: ~d
|
NarSize: ~d
|
||||||
References: ~a~%"
|
References: ~a
|
||||||
|
FileSize: ~a~%"
|
||||||
%item
|
%item
|
||||||
(basename %item)
|
(basename %item)
|
||||||
(bytevector->nix-base32-string
|
(bytevector->nix-base32-string
|
||||||
(path-info-hash info))
|
(path-info-hash info))
|
||||||
(path-info-nar-size info)
|
(path-info-nar-size info)
|
||||||
(basename (first (path-info-references info)))))
|
(basename (first (path-info-references info)))
|
||||||
|
(path-info-nar-size info)))
|
||||||
(signature (base64-encode
|
(signature (base64-encode
|
||||||
(string->utf8
|
(string->utf8
|
||||||
(canonical-sexp->string
|
(canonical-sexp->string
|
||||||
|
@ -152,11 +154,13 @@ (define (wait-until-ready port)
|
||||||
Compression: none
|
Compression: none
|
||||||
NarHash: sha256:~a
|
NarHash: sha256:~a
|
||||||
NarSize: ~d
|
NarSize: ~d
|
||||||
References: ~%"
|
References: ~%\
|
||||||
|
FileSize: ~a~%"
|
||||||
item
|
item
|
||||||
(uri-encode (basename item))
|
(uri-encode (basename item))
|
||||||
(bytevector->nix-base32-string
|
(bytevector->nix-base32-string
|
||||||
(path-info-hash info))
|
(path-info-hash info))
|
||||||
|
(path-info-nar-size info)
|
||||||
(path-info-nar-size info)))
|
(path-info-nar-size info)))
|
||||||
(signature (base64-encode
|
(signature (base64-encode
|
||||||
(string->utf8
|
(string->utf8
|
||||||
|
@ -323,6 +327,7 @@ (define (wait-until-ready port)
|
||||||
("Compression" . "gzip"))
|
("Compression" . "gzip"))
|
||||||
200 ;nar/gzip/…
|
200 ;nar/gzip/…
|
||||||
#t ;Content-Length
|
#t ;Content-Length
|
||||||
|
#t ;FileSize
|
||||||
200) ;nar/…
|
200) ;nar/…
|
||||||
(call-with-temporary-directory
|
(call-with-temporary-directory
|
||||||
(lambda (cache)
|
(lambda (cache)
|
||||||
|
@ -351,10 +356,11 @@ (define (wait-for-file file)
|
||||||
(response (http-get url)))
|
(response (http-get url)))
|
||||||
(and (= 404 (response-code response))
|
(and (= 404 (response-code response))
|
||||||
(wait-for-file cached)
|
(wait-for-file cached)
|
||||||
(let ((body (http-get-port url))
|
(let* ((body (http-get-port url))
|
||||||
(compressed (http-get nar-url))
|
(compressed (http-get nar-url))
|
||||||
(uncompressed (http-get (string-append base "nar/"
|
(uncompressed (http-get (string-append base "nar/"
|
||||||
(basename %item)))))
|
(basename %item))))
|
||||||
|
(narinfo (recutils->alist body)))
|
||||||
(list (file-exists? nar)
|
(list (file-exists? nar)
|
||||||
(filter (lambda (item)
|
(filter (lambda (item)
|
||||||
(match item
|
(match item
|
||||||
|
@ -362,10 +368,13 @@ (define (wait-for-file file)
|
||||||
(("StorePath" . _) #t)
|
(("StorePath" . _) #t)
|
||||||
(("URL" . _) #t)
|
(("URL" . _) #t)
|
||||||
(_ #f)))
|
(_ #f)))
|
||||||
(recutils->alist body))
|
narinfo)
|
||||||
(response-code compressed)
|
(response-code compressed)
|
||||||
(= (response-content-length compressed)
|
(= (response-content-length compressed)
|
||||||
(stat:size (stat nar)))
|
(stat:size (stat nar)))
|
||||||
|
(= (string->number
|
||||||
|
(assoc-ref narinfo "FileSize"))
|
||||||
|
(stat:size (stat nar)))
|
||||||
(response-code uncompressed)))))))))
|
(response-code uncompressed)))))))))
|
||||||
|
|
||||||
(test-end "publish")
|
(test-end "publish")
|
||||||
|
|
Loading…
Reference in a new issue