@@ -15,27 +15,47 @@ Derivation derivationFromPath(StoreAPI & store, const Path & drvPath)
15
15
}
16
16
17
17
18
- void computeFSClosure (StoreAPI & store, const Path & storePath ,
19
- PathSet & paths, bool flipDirection, bool includeOutputs)
18
+ void computeFSClosure (StoreAPI & store, const Path & path ,
19
+ PathSet & paths, bool flipDirection, bool includeOutputs, bool includeDerivers )
20
20
{
21
- if (paths.find (storePath ) != paths.end ()) return ;
22
- paths.insert (storePath );
21
+ if (paths.find (path ) != paths.end ()) return ;
22
+ paths.insert (path );
23
23
24
- PathSet references;
25
- if (flipDirection)
26
- store.queryReferrers (storePath, references);
27
- else
28
- store.queryReferences (storePath, references);
29
-
30
- if (includeOutputs && isDerivation (storePath)) {
31
- PathSet outputs = store.queryDerivationOutputs (storePath);
32
- foreach (PathSet::iterator, i, outputs)
33
- if (store.isValidPath (*i))
34
- computeFSClosure (store, *i, paths, flipDirection, true );
24
+ PathSet edges;
25
+
26
+ if (flipDirection) {
27
+ store.queryReferrers (path, edges);
28
+
29
+ if (includeOutputs) {
30
+ PathSet derivers = store.queryValidDerivers (path);
31
+ foreach (PathSet::iterator, i, derivers)
32
+ edges.insert (*i);
33
+ }
34
+
35
+ if (includeDerivers && isDerivation (path)) {
36
+ PathSet outputs = store.queryDerivationOutputs (path);
37
+ foreach (PathSet::iterator, i, outputs)
38
+ if (store.isValidPath (*i) && store.queryDeriver (*i) == path)
39
+ edges.insert (*i);
40
+ }
41
+
42
+ } else {
43
+ store.queryReferences (path, edges);
44
+
45
+ if (includeOutputs && isDerivation (path)) {
46
+ PathSet outputs = store.queryDerivationOutputs (path);
47
+ foreach (PathSet::iterator, i, outputs)
48
+ if (store.isValidPath (*i)) edges.insert (*i);
49
+ }
50
+
51
+ if (includeDerivers) {
52
+ Path deriver = store.queryDeriver (path);
53
+ if (store.isValidPath (deriver)) edges.insert (deriver);
54
+ }
35
55
}
36
56
37
- foreach (PathSet::iterator, i, references )
38
- computeFSClosure (store, *i, paths, flipDirection, includeOutputs);
57
+ foreach (PathSet::iterator, i, edges )
58
+ computeFSClosure (store, *i, paths, flipDirection, includeOutputs, includeDerivers );
39
59
}
40
60
41
61
0 commit comments