From f10dcbf1a92c147a2fedba6f774afa6a7013fcdf Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 22 Jun 2016 23:46:32 +0200 Subject: substitute: Use ~/.cache when invoked by an unprivileged user. This is a followup to ea0c6e0507a6997f12a4f29d0445b51cf53bd81e. * guix/scripts/substitute.scm (%narinfo-cache-directory): Use 'cache-directory' when (getuid) returns non-zero. (cache-narinfo!): Remove 'catch'. --- guix/scripts/substitute.scm | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'guix/scripts/substitute.scm') diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index 81ce770dc5..5722aa821d 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -94,10 +94,15 @@ ;;; Code: (define %narinfo-cache-directory - ;; A local cache of narinfos, to avoid going to the network. - (or (and=> (getenv "XDG_CACHE_HOME") - (cut string-append <> "/guix/substitute")) - (string-append %state-directory "/substitute/cache"))) + ;; A local cache of narinfos, to avoid going to the network. Most of the + ;; time, 'guix substitute' is called by guix-daemon as root and stores its + ;; cached data in /var/guix/…. However, when invoked from 'guix challenge' + ;; as a user, it stores its cache in ~/.cache. + (if (zero? (getuid)) + (or (and=> (getenv "XDG_CACHE_HOME") + (cut string-append <> "/guix/substitute")) + (string-append %state-directory "/substitute/cache")) + (string-append (cache-directory) "/substitute"))) (define %allow-unauthenticated-substitutes? ;; Whether to allow unchecked substitutes. This is useful for testing @@ -501,17 +506,10 @@ indicates that PATH is unavailable at CACHE-URL." (value ,(and=> narinfo narinfo->string)))) (let ((file (narinfo-cache-file cache-url path))) - (catch 'system-error - (lambda () - (mkdir-p (dirname file)) - (with-atomic-file-output file - (lambda (out) - (write (cache-entry cache-url narinfo) out)))) - (lambda args - ;; We may not have write access to the local cache when called from an - ;; unprivileged process such as 'guix challenge'. - (unless (= EACCES (system-error-errno args)) - (apply throw args))))) + (mkdir-p (dirname file)) + (with-atomic-file-output file + (lambda (out) + (write (cache-entry cache-url narinfo) out)))) narinfo) -- cgit v1.2.3 From a7a3b390600351014bee523cadb25c9a242064e9 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 14 Jul 2016 15:19:07 +0200 Subject: substitute: Gracefully handle trailing slashes in URLs. Previously, using something like "--substitute-urls=http://example.org///" would lead to a 'cache-narinfo!' call with #f as its second argument. It would also do the wrong thing for URLs with a non-empty initial path component, such as "http://example.org/foo/bar". * guix/scripts/substitute.scm (fetch-narinfos)[handle-narinfo-response]: Add call to 'basename' for PATH. --- guix/scripts/substitute.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'guix/scripts/substitute.scm') diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index 5722aa821d..8827c45fb8 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -610,7 +610,8 @@ if file doesn't exist, and the narinfo otherwise." (update-progress!) (cons narinfo result)) (let* ((path (uri-path (request-uri request))) - (hash-part (string-drop-right path 8))) ; drop ".narinfo" + (hash-part (basename + (string-drop-right path 8)))) ;drop ".narinfo" (if len (get-bytevector-n port len) (read-to-eof port)) -- cgit v1.2.3