aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-06-13 22:03:42 +0200
committerLudovic Courtès <ludo@gnu.org>2013-06-13 22:03:42 +0200
commit3f1e69395cbfaad80710bdfbef433c26aa216271 (patch)
tree4937f847fc6c22f5595f6d75d9e7b1f15cbf8a7c /guix
parentd4c748607995bec8a13f058bdeba89e41ff6539c (diff)
downloadgnu-guix-3f1e69395cbfaad80710bdfbef433c26aa216271.tar
gnu-guix-3f1e69395cbfaad80710bdfbef433c26aa216271.tar.gz
store: Add `requisites'.
* guix/store.scm (fold-path, requisites): New procedures. * tests/store.scm ("requisites"): New test.
Diffstat (limited to 'guix')
-rw-r--r--guix/store.scm26
1 files changed, 26 insertions, 0 deletions
diff --git a/guix/store.scm b/guix/store.scm
index d15ba1275f..57e1ca06aa 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -31,6 +31,7 @@
#:use-module (srfi srfi-39)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
+ #:use-module (ice-9 vlist)
#:export (%daemon-socket-file
nix-server?
@@ -70,6 +71,7 @@
substitutable-path-info
references
+ requisites
referrers
valid-derivers
query-derivation-outputs
@@ -493,6 +495,30 @@ file name. Return #t on success."
"Return the list of references of PATH."
store-path-list))
+(define* (fold-path store proc seed path
+ #:optional (relatives (cut references store <>)))
+ "Call PROC for each of the RELATIVES of PATH, exactly once, and return the
+result formed from the successive calls to PROC, the first of which is passed
+SEED."
+ (let loop ((paths (list path))
+ (result seed)
+ (seen vlist-null))
+ (match paths
+ ((path rest ...)
+ (if (vhash-assoc path seen)
+ (loop rest result seen)
+ (let ((seen (vhash-cons path #t seen))
+ (rest (append rest (relatives path)))
+ (result (proc path result)))
+ (loop rest result seen))))
+ (()
+ result))))
+
+(define (requisites store path)
+ "Return the requisites of PATH, including PATH---i.e., its closure (all its
+references, recursively)."
+ (fold-path store cons '() path))
+
(define referrers
(operation (query-referrers (store-path path))
"Return the list of path that refer to PATH."