Skip to content
Snippets Groups Projects
Commit ecdb81e1 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

guix-download: Gracefully handle invalid URIs.

* guix-download.in (guix-download): Error out when `string->uri'
  returns #f.  Use `leave' when the scheme is unknown.
* tests/guix-download.sh: Add tests.
parent db32c281
No related branches found
No related tags found
No related merge requests found
......@@ -159,16 +159,15 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@"))
(let* ((opts (parse-options))
(store (open-connection))
(uri (string->uri (assq-ref opts 'argument)))
(uri (or (string->uri (assq-ref opts 'argument))
(leave (_ "guix-download: ~a: failed to parse URI~%")
(assq-ref opts 'argument))))
(fetch (case (uri-scheme uri)
((http) http-fetch)
((ftp) ftp-fetch)
(else
(begin
(format (current-error-port)
(_ "guix-download: ~a: unsupported URI scheme~%")
(uri-scheme uri))
(exit 1)))))
(leave (_ "guix-download: ~a: unsupported URI scheme~%")
(uri-scheme uri)))))
(path (call-with-temporary-output-file
(lambda (name port)
(fetch uri port)
......
......@@ -25,3 +25,9 @@ guix-download --version
# Make sure it fails here.
if guix-download http://www.example.com/does-not-exist
then false; else true; fi
if guix-download unknown://some/where;
then false; else true; fi
if guix-download not/a/uri;
then false; else true; fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment