aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/utils.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix-build-coordinator/utils.scm')
-rw-r--r--guix-build-coordinator/utils.scm50
1 files changed, 50 insertions, 0 deletions
diff --git a/guix-build-coordinator/utils.scm b/guix-build-coordinator/utils.scm
index ef26d3a..7b38130 100644
--- a/guix-build-coordinator/utils.scm
+++ b/guix-build-coordinator/utils.scm
@@ -36,6 +36,7 @@
call-with-streaming-http-request
make-chunked-input-port*
+ find-missing-substitutes-for-output
has-substiutes-no-cache?
substitute-derivation
@@ -256,6 +257,55 @@ upcoming chunk."
(values response
body))))))))
+(define (find-missing-substitutes-for-output substitute-urls output)
+ (define %narinfo-cache-directory
+ (if (zero? (getuid))
+ (or (and=> (getenv "XDG_CACHE_HOME")
+ (cut string-append <> "/guix/substitute"))
+ (string-append %state-directory "/substitute/cache"))
+ (string-append (cache-directory #:ensure? #f) "/substitute")))
+
+ ;; Because there's no control over the caching of 404 lookups, and I'd
+ ;; rather not reach inside and monkey patch the Guix code, just delete any
+ ;; cache files
+ (let ((hash-part (store-path-hash-part output))
+ (directories
+ (scandir %narinfo-cache-directory
+ (lambda (s) (= (string-length s) 52)))))
+
+ (for-each (lambda (directory)
+ (let ((cache-file
+ (string-append
+ %narinfo-cache-directory "/"
+ directory "/" hash-part)))
+ (when (file-exists? cache-file)
+ (with-exception-handler
+ (lambda (exn)
+ (simple-format
+ (current-error-port)
+ "error: when deleting substitute cache file: ~A\n"
+ exn))
+ (lambda ()
+ (delete-file cache-file))
+ #:unwind? #t))))
+ (or directories '())))
+
+ (let ((narinfo
+ (any (lambda (substitute-url)
+ (let ((result (lookup-narinfos substitute-url (list output))))
+ (if (null? result)
+ #f
+ (first result))))
+ substitute-urls)))
+ (if narinfo
+ (append-map
+ (lambda (referenced-output)
+ (peek "REF" referenced-output)
+ (find-missing-substitutes-for-output substitute-urls
+ referenced-output))
+ (narinfo-references narinfo))
+ (list output))))
+
(define (has-substiutes-no-cache? substitute-urls file)
(define %narinfo-cache-directory
(if (zero? (getuid))