aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-data-service/web/nar/controller.scm96
1 files changed, 51 insertions, 45 deletions
diff --git a/guix-data-service/web/nar/controller.scm b/guix-data-service/web/nar/controller.scm
index 781a01b..9c46eb5 100644
--- a/guix-data-service/web/nar/controller.scm
+++ b/guix-data-service/web/nar/controller.scm
@@ -81,51 +81,10 @@
conn
(string-append "/gnu/store/" file-name)))
(('GET (? .narinfo-suffix path))
- (let* ((hash (string-drop-right
- path
- (string-length ".narinfo")))
- (derivation (select-derivation-by-file-name-hash
- conn
- hash)))
- (if derivation
- (list (build-response
- #:code 200
- #:headers '((content-type . (application/x-narinfo))))
- (let* ((derivation-file-name
- (second derivation))
- (derivation-text
- (select-serialized-derivation-by-file-name
- conn
- derivation-file-name))
- (derivation-bytevector
- (string->bytevector derivation-text
- "ISO-8859-1"))
- (derivation-references
- (select-derivation-references-by-derivation-id
- conn
- (first derivation)))
- (nar-bytevector
- (call-with-values
- (lambda ()
- (open-bytevector-output-port))
- (lambda (port get-bytevector)
- (write-file-tree
- derivation-file-name
- port
- #:file-type+size
- (lambda (file)
- (values 'regular
- (bytevector-length derivation-bytevector)))
- #:file-port
- (lambda (file)
- (open-bytevector-input-port derivation-bytevector)))
- (get-bytevector)))))
- (lambda (port)
- (display (narinfo-string derivation-file-name
- nar-bytevector
- derivation-references)
- port))))
- (not-found (request-uri request)))))
+ (render-narinfo request
+ conn
+ (string-drop-right path
+ (string-length ".narinfo"))))
(_ #f)))
(define (render-nar request
@@ -171,6 +130,53 @@
(put-bytevector port data)))))
(not-found (request-uri request))))
+(define (render-narinfo request
+ conn
+ hash)
+ (or
+ (and=> (select-derivation-by-file-name-hash conn
+ hash)
+ (lambda (derivation)
+ (list (build-response
+ #:code 200
+ #:headers '((content-type . (application/x-narinfo))))
+ (let* ((derivation-file-name
+ (second derivation))
+ (derivation-text
+ (select-serialized-derivation-by-file-name
+ conn
+ derivation-file-name))
+ (derivation-bytevector
+ (string->bytevector derivation-text
+ "ISO-8859-1"))
+ (derivation-references
+ (select-derivation-references-by-derivation-id
+ conn
+ (first derivation)))
+ (nar-bytevector
+ (call-with-values
+ (lambda ()
+ (open-bytevector-output-port))
+ (lambda (port get-bytevector)
+ (write-file-tree
+ derivation-file-name
+ port
+ #:file-type+size
+ (lambda (file)
+ (values 'regular
+ (bytevector-length derivation-bytevector)))
+ #:file-port
+ (lambda (file)
+ (open-bytevector-input-port derivation-bytevector)))
+ (get-bytevector)))))
+ (lambda (port)
+ (display (narinfo-string derivation-file-name
+ nar-bytevector
+ derivation-references)
+ port))))))
+ (not-found (request-uri request))))
+
+
(define* (narinfo-string store-item
nar-bytevector
references