Patchwork utils: file-extension should work with urls.

login
register
mail settings
Submitter David Craven
Date Dec. 14, 2016, 3:25 p.m.
Message ID <20161214152507.17677-1-david@craven.ch>
Download mbox | patch
Permalink /patch/18454/
State New
Headers show

Comments

David Craven - Dec. 14, 2016, 3:25 p.m.
* guix/utils.scm (file-extension): Detect the lack of file extensions in
  urls.
---
 guix/utils.scm | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
David Craven - Dec. 14, 2016, 3:26 p.m.
This patch causes a test failure. Any ideas on how to do it better?
I'll push the rust stuff in the meantime, since there is nothing
technically wrong with the updater itself.

test-name: /*.narinfo for a compressed file
location: /home/dvc/guix/tests/publish.scm:218
source:
+ (test-equal
+   "/*.narinfo for a compressed file"
+   '("none" "nar")
+   (let* ((item (add-text-to-store
+                  %store
+                  "fake.tar.gz"
+                  "This is a fake compressed file."))
+          (url (string-append
+                 "http://localhost:6799/"
+                 (store-path-hash-part item)
+                 ".narinfo"))
+          (body (http-get-port url))
+          (info (recutils->alist body)))
+     (list (assoc-ref info "Compression")
+           (dirname (assoc-ref info "URL")))))
expected-value: (none nar)
actual-value: (gzip nar/gzip)
result: FAIL
David Craven - Dec. 15, 2016, 4:27 a.m.
> guix/utils.scm (file-extension): Detect the lack of file extensions in urls.

This is so stupid. Just to cover up some other stupidity I did earlier that day.
David Craven - Dec. 15, 2016, 5:01 a.m.
Fixed yesterdays stupidity with 6976c68158e9c6bb264ca48041da5be1c24521cf

Patch

diff --git a/guix/utils.scm b/guix/utils.scm
index 06f49daca..2bae2eb60 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -24,6 +24,7 @@ 
 (define-module (guix utils)
   #:use-module (guix config)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-2)
   #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-26)
@@ -559,8 +560,11 @@  minor version numbers from version-string."
 
 (define (file-extension file)
   "Return the extension of FILE or #f if there is none."
-  (let ((dot (string-rindex file #\.)))
-    (and dot (substring file (+ 1 dot) (string-length file)))))
+  (and-let* ((dot (string-rindex file #\.))
+             (ext (substring file (+ 1 dot) (string-length file))))
+    ;; Make sure that a file-extension does not contain forward
+    ;; slashes incase file is a URL.
+    (and (not (string-rindex file #\/)) ext)))
 
 (define (file-sans-extension file)
   "Return the substring of FILE without its extension, if any."