diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-12-20T17·41+0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-12-20T17·41+0100 |
commit | 2754a07eadfa3fe263f83830c701748bbd4c0420 (patch) | |
tree | da273ff0e02a7aa7eb00345f1f1b0ca23ba88643 /src/libstore/misc.cc | |
parent | 06f62defe640517267a6a16dd222076c822f3123 (diff) |
nix-store -q --roots: Respect the gc-keep-outputs/gc-keep-derivations settings
So if a path is not garbage solely because it's reachable from a root due to the gc-keep-outputs or gc-keep-derivations settings, ‘nix-store -q --roots’ now shows that root.
Diffstat (limited to 'src/libstore/misc.cc')
-rw-r--r-- | src/libstore/misc.cc | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index 899e4764c1d6..74ff26b9cc5c 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -15,27 +15,47 @@ Derivation derivationFromPath(StoreAPI & store, const Path & drvPath) } -void computeFSClosure(StoreAPI & store, const Path & storePath, - PathSet & paths, bool flipDirection, bool includeOutputs) +void computeFSClosure(StoreAPI & store, const Path & path, + PathSet & paths, bool flipDirection, bool includeOutputs, bool includeDerivers) { - if (paths.find(storePath) != paths.end()) return; - paths.insert(storePath); + if (paths.find(path) != paths.end()) return; + paths.insert(path); - PathSet references; - if (flipDirection) - store.queryReferrers(storePath, references); - else - store.queryReferences(storePath, references); - - if (includeOutputs && isDerivation(storePath)) { - PathSet outputs = store.queryDerivationOutputs(storePath); - foreach (PathSet::iterator, i, outputs) - if (store.isValidPath(*i)) - computeFSClosure(store, *i, paths, flipDirection, true); + PathSet edges; + + if (flipDirection) { + store.queryReferrers(path, edges); + + if (includeOutputs) { + PathSet derivers = store.queryValidDerivers(path); + foreach (PathSet::iterator, i, derivers) + edges.insert(*i); + } + + if (includeDerivers && isDerivation(path)) { + PathSet outputs = store.queryDerivationOutputs(path); + foreach (PathSet::iterator, i, outputs) + if (store.isValidPath(*i) && store.queryDeriver(*i) == path) + edges.insert(*i); + } + + } else { + store.queryReferences(path, edges); + + if (includeOutputs && isDerivation(path)) { + PathSet outputs = store.queryDerivationOutputs(path); + foreach (PathSet::iterator, i, outputs) + if (store.isValidPath(*i)) edges.insert(*i); + } + + if (includeDerivers) { + Path deriver = store.queryDeriver(path); + if (store.isValidPath(deriver)) edges.insert(deriver); + } } - foreach (PathSet::iterator, i, references) - computeFSClosure(store, *i, paths, flipDirection, includeOutputs); + foreach (PathSet::iterator, i, edges) + computeFSClosure(store, *i, paths, flipDirection, includeOutputs, includeDerivers); } |