diff options
author | Christopher Baines <mail@cbaines.net> | 2023-05-21 22:19:35 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-05-21 22:19:35 +0100 |
commit | b2b8b37c112c676fffe8d65a86d96690ae97d20e (patch) | |
tree | 0243f7f601e9ae82e3b0091d43d08674a858f0ad | |
parent | 8a9747b3c66adbab9dc5411d6c54b0676b2d9117 (diff) | |
download | nar-herder-b2b8b37c112c676fffe8d65a86d96690ae97d20e.tar nar-herder-b2b8b37c112c676fffe8d65a86d96690ae97d20e.tar.gz |
Better handle /file requests where the nar is known but unavailable
-rw-r--r-- | nar-herder/server.scm | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/nar-herder/server.scm b/nar-herder/server.scm index ec1b4ae..07cb1c4 100644 --- a/nar-herder/server.scm +++ b/nar-herder/server.scm @@ -390,35 +390,38 @@ ;; TODO Select intelligently (if (null? narinfo-files) #f - (first narinfo-files)))) + (first narinfo-files))) + (filename + (and selected-narinfo-file + (let ((filename + (string-append + storage-root + (uri-decode + (assq-ref selected-narinfo-file 'url))))) + (and (file-exists? filename) + filename))))) (increment-request-metric "file" - (if selected-narinfo-file "200" "404")) - - (if selected-narinfo-file - (let* ((url - (assq-ref selected-narinfo-file 'url)) - (filename - (string-append storage-root - (uri-decode url)))) - - (serve-fixed-output-file - (open-input-file filename) - (assq-ref selected-narinfo-file - 'compression) - (lambda (nar-port bytes) - (values `((content-type . (application/octet-stream - (charset . "ISO-8859-1"))) - (content-length . ,bytes)) - (if (eq? (request-method request) 'HEAD) - #f - (lambda (output-port) - (dump-port nar-port - output-port - bytes) - - (close-port output-port))))))) + (if filename "200" "404")) + + (if filename + (serve-fixed-output-file + (open-input-file filename) + (assq-ref selected-narinfo-file + 'compression) + (lambda (nar-port bytes) + (values `((content-type . (application/octet-stream + (charset . "ISO-8859-1"))) + (content-length . ,bytes)) + (if (eq? (request-method request) 'HEAD) + #f + (lambda (output-port) + (dump-port nar-port + output-port + bytes) + + (close-port output-port)))))) (values (build-response #:code 404) (if (eq? (request-method request) 'HEAD) |