diff options
author | Ludovic Courtès <ludo@gnu.org> | 2016-05-20 17:18:58 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2016-05-21 01:35:14 +0200 |
commit | 30d4bc0434aa5d438c2d433f39c80e1f4a25bcac (patch) | |
tree | 40f8d0071ba458cbf1761c2b20240bdb5fda12ac | |
parent | a773c3142dd168e1c4480614d3f5fd9d003954cd (diff) | |
download | gnu-guix-30d4bc0434aa5d438c2d433f39c80e1f4a25bcac.tar gnu-guix-30d4bc0434aa5d438c2d433f39c80e1f4a25bcac.tar.gz |
substitute: Gracefully handle invalid store file names.
Before, something like:
echo have /gnu/foo | ./test-env guix substitute --query
would lead to an ugly backtrace.
* guix/scripts/substitute.scm (narinfo-cache-file): Call 'leave' when
'store-hash-part' returns #f.
-rwxr-xr-x | guix/scripts/substitute.scm | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index d46d610347..5cdc55f2b2 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -440,9 +440,15 @@ the cache STR originates form." (define (narinfo-cache-file cache-url path) "Return the name of the local file that contains an entry for PATH. The entry is stored in a sub-directory specific to CACHE-URL." - (string-append %narinfo-cache-directory "/" - (bytevector->base32-string (sha256 (string->utf8 cache-url))) - "/" (store-path-hash-part path))) + ;; The daemon does not sanitize its input, so PATH could be something like + ;; "/gnu/store/foo". Gracefully handle that. + (match (store-path-hash-part path) + (#f + (leave (_ "'~a' does not name a store item~%") path)) + ((? string? hash-part) + (string-append %narinfo-cache-directory "/" + (bytevector->base32-string (sha256 (string->utf8 cache-url))) + "/" hash-part)))) (define (cached-narinfo cache-url path) "Check locally if we have valid info about PATH coming from CACHE-URL. |