guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Ludovic Courtès
Date: Thu, 24 Aug 2023 11:21:34 -0400 (EDT)

branch: master
commit 103a6ec27b42346f942cb5ff7c2398ca9340a58e
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu Aug 24 14:54:55 2023 +0200

    http: Gracefully handle missing files in "/download".
    
    Partly fixes <https://issues.guix.gnu.org/64317>.
    
    * src/cuirass/http.scm (url-handler): Catch 'system-error around
    'respond-file'; return 500 upon ENOENT.  Pass #:ttl to 'respond-file'.
---
 src/cuirass/http.scm | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 26020de..2350be2 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -1180,12 +1180,19 @@ passed, only display JOBS targeting this SYSTEM."
        '())))
 
     (('GET "download" id)
-     (let ((path (db-get-build-product-path id)))
-       (if path
-           (respond-file path)
-           (respond-json-with-error
-            404
-            "Could not find the request build product."))))
+     (let ((file (db-get-build-product-path id))
+           (fail (lambda (code)
+                   (respond-json-with-error
+                    code "Could not find the requested build product."))))
+       (if file
+           (catch 'system-error
+             (lambda ()
+               (respond-file file #:ttl %static-file-ttl))
+             (lambda args
+               (if (= ENOENT (system-error-errno args))
+                   (fail 500)                  ;something's wrong: it vanished
+                   (apply throw args))))
+           (fail 404))))                          ;no such build product
 
     (('GET "machine" name)
      (respond-html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]