substitute: Use ~/.cache when invoked by an unprivileged user.

This is a followup to ea0c6e0507.

* guix/scripts/substitute.scm (%narinfo-cache-directory): Use
'cache-directory' when (getuid) returns non-zero.
(cache-narinfo!): Remove 'catch'.
This commit is contained in:
Ludovic Courtès 2016-06-22 23:46:32 +02:00
parent 3583b27b2c
commit f10dcbf1a9
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 13 additions and 15 deletions

View File

@ -94,10 +94,15 @@
;;; Code: ;;; Code:
(define %narinfo-cache-directory (define %narinfo-cache-directory
;; A local cache of narinfos, to avoid going to the network. ;; A local cache of narinfos, to avoid going to the network. Most of the
(or (and=> (getenv "XDG_CACHE_HOME") ;; time, 'guix substitute' is called by guix-daemon as root and stores its
(cut string-append <> "/guix/substitute")) ;; cached data in /var/guix/…. However, when invoked from 'guix challenge'
(string-append %state-directory "/substitute/cache"))) ;; 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? (define %allow-unauthenticated-substitutes?
;; Whether to allow unchecked substitutes. This is useful for testing ;; 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)))) (value ,(and=> narinfo narinfo->string))))
(let ((file (narinfo-cache-file cache-url path))) (let ((file (narinfo-cache-file cache-url path)))
(catch 'system-error (mkdir-p (dirname file))
(lambda () (with-atomic-file-output file
(mkdir-p (dirname file)) (lambda (out)
(with-atomic-file-output file (write (cache-entry cache-url narinfo) out))))
(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)))))
narinfo) narinfo)