From 35db4f65a0f2ccbcaaef719e52b895fa78cad361 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 7 Oct 2016 19:15:25 +0200 Subject: [PATCH] Add copyClosure utility function for Hydra --- src/libstore/store-api.cc | 24 ++++++++++++++++++++++++ src/libstore/store-api.hh | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 90e174715..74014b47e 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -414,6 +414,30 @@ void copyStorePath(ref srcStore, ref dstStore, } +void copyClosure(ref srcStore, ref dstStore, + const PathSet & storePaths, bool repair) +{ + PathSet closure; + for (auto & path : storePaths) + srcStore->computeFSClosure(path, closure); + + PathSet valid = dstStore->queryValidPaths(closure); + + if (valid.size() == closure.size()) return; + + Paths sorted = srcStore->topoSortPaths(closure); + + Paths missing; + for (auto i = sorted.rbegin(); i != sorted.rend(); ++i) + if (!valid.count(*i)) missing.push_back(*i); + + printMsg(lvlDebug, format("copying %1% missing paths") % missing.size()); + + for (auto & i : missing) + copyStorePath(srcStore, dstStore, i, repair); +} + + ValidPathInfo decodeValidPathInfo(std::istream & str, bool hashGiven) { ValidPathInfo info; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 8efacfd18..b876ffbba 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -585,6 +585,11 @@ void copyStorePath(ref srcStore, ref dstStore, const Path & storePath, bool repair = false); +/* Copy the closure of the specified paths from one store to another. */ +void copyClosure(ref srcStore, ref dstStore, + const PathSet & storePaths, bool repair = false); + + /* Remove the temporary roots file for this process. Any temporary root becomes garbage after this point unless it has been registered as a (permanent) root. */