Make computeFSClosure ca-aware

Fix #4820 by preventing nix-collect garbage from crashing if
`keep-outputs` or `keep-derivations` is true
This commit is contained in:
regnat 2021-06-11 09:24:24 +02:00
parent 8e6ee1b9e9
commit 7ac038fa4b

View file

@ -29,9 +29,9 @@ void Store::computeFSClosure(const StorePathSet & startPaths,
res.insert(i); res.insert(i);
if (includeDerivers && path.isDerivation()) if (includeDerivers && path.isDerivation())
for (auto& i : queryDerivationOutputs(path)) for (auto& [_, maybeOutPath] : queryPartialDerivationOutputMap(path))
if (isValidPath(i) && queryPathInfo(i)->deriver == path) if (maybeOutPath && isValidPath(*maybeOutPath) && queryPathInfo(*maybeOutPath)->deriver == path)
res.insert(i); res.insert(*maybeOutPath);
return res; return res;
}; };
else else
@ -44,9 +44,9 @@ void Store::computeFSClosure(const StorePathSet & startPaths,
res.insert(ref); res.insert(ref);
if (includeOutputs && path.isDerivation()) if (includeOutputs && path.isDerivation())
for (auto& i : queryDerivationOutputs(path)) for (auto& [_, maybeOutPath] : queryPartialDerivationOutputMap(path))
if (isValidPath(i)) if (maybeOutPath && isValidPath(*maybeOutPath))
res.insert(i); res.insert(*maybeOutPath);
if (includeDerivers && info->deriver && isValidPath(*info->deriver)) if (includeDerivers && info->deriver && isValidPath(*info->deriver))
res.insert(*info->deriver); res.insert(*info->deriver);