libstore: asyncify copyPaths

Change-Id: Ie7cd94d8760abd9c7593f73fd281cbba91a5be77
This commit is contained in:
eldritch horrors
2025-02-08 13:50:33 +00:00
parent fb9e3f6cb5
commit 9b0cd7a7c9
5 changed files with 36 additions and 22 deletions
+11 -2
View File
@@ -285,7 +285,14 @@ connected:
{
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying dependencies to '%s'", storeUri));
copyPaths(*store, *sshStore, store->parseStorePathSet(inputs), NoRepair, NoCheckSigs, substitute);
aio.blockOn(copyPaths(
*store,
*sshStore,
store->parseStorePathSet(inputs),
NoRepair,
NoCheckSigs,
substitute
));
}
uploadLock.reset();
@@ -371,7 +378,9 @@ connected:
if (auto localStore = store.dynamic_pointer_cast<LocalStore>())
for (auto & path : missingPaths)
localStore->locksHeld.insert(store->printStorePath(path)); /* FIXME: ugly */
copyPaths(*sshStore, *store, missingPaths, NoRepair, NoCheckSigs, NoSubstitute);
aio.blockOn(
copyPaths(*sshStore, *store, missingPaths, NoRepair, NoCheckSigs, NoSubstitute)
);
}
// XXX: Should be done as part of `copyPaths`
for (auto & realisation : missingRealisations) {
+20 -15
View File
@@ -1141,14 +1141,14 @@ void copyStorePath(
}
std::map<StorePath, StorePath> copyPaths(
kj::Promise<Result<std::map<StorePath, StorePath>>> copyPaths(
Store & srcStore,
Store & dstStore,
const RealisedPath::Set & paths,
RepairFlag repair,
CheckSigsFlag checkSigs,
SubstituteFlag substitute)
{
try {
StorePathSet storePaths;
std::set<Realisation> toplevelRealisations;
for (auto & path : paths) {
@@ -1158,7 +1158,8 @@ std::map<StorePath, StorePath> copyPaths(
toplevelRealisations.insert(*realisation);
}
}
auto pathsMap = copyPaths(srcStore, dstStore, storePaths, repair, checkSigs, substitute);
auto pathsMap =
TRY_AWAIT(copyPaths(srcStore, dstStore, storePaths, repair, checkSigs, substitute));
try {
// Copy the realisation closure
@@ -1190,17 +1191,19 @@ std::map<StorePath, StorePath> copyPaths(
throw;
}
return pathsMap;
co_return pathsMap;
} catch (...) {
co_return result::current_exception();
}
std::map<StorePath, StorePath> copyPaths(
kj::Promise<Result<std::map<StorePath, StorePath>>> copyPaths(
Store & srcStore,
Store & dstStore,
const StorePathSet & storePaths,
RepairFlag repair,
CheckSigsFlag checkSigs,
SubstituteFlag substitute)
{
try {
auto valid = dstStore.queryValidPaths(storePaths, substitute);
StorePathSet missing;
@@ -1285,7 +1288,9 @@ std::map<StorePath, StorePath> copyPaths(
dstStore.addMultipleToStore(pathsToCopy, act, repair, checkSigs);
return pathsMap;
co_return pathsMap;
} catch (...) {
co_return result::current_exception();
}
kj::Promise<Result<void>> copyClosure(
@@ -1296,15 +1301,15 @@ kj::Promise<Result<void>> copyClosure(
CheckSigsFlag checkSigs,
SubstituteFlag substitute)
try {
if (&srcStore == &dstStore) return {result::success()};
if (&srcStore == &dstStore) co_return result::success();
RealisedPath::Set closure;
RealisedPath::closure(srcStore, paths, closure);
copyPaths(srcStore, dstStore, closure, repair, checkSigs, substitute);
return {result::success()};
TRY_AWAIT(copyPaths(srcStore, dstStore, closure, repair, checkSigs, substitute));
co_return result::success();
} catch (...) {
return {result::current_exception()};
co_return result::current_exception();
}
kj::Promise<Result<void>> copyClosure(
@@ -1315,14 +1320,14 @@ kj::Promise<Result<void>> copyClosure(
CheckSigsFlag checkSigs,
SubstituteFlag substitute)
try {
if (&srcStore == &dstStore) return {result::success()};
if (&srcStore == &dstStore) co_return result::success();
StorePathSet closure;
srcStore.computeFSClosure(storePaths, closure);
copyPaths(srcStore, dstStore, closure, repair, checkSigs, substitute);
return {result::success()};
TRY_AWAIT(copyPaths(srcStore, dstStore, closure, repair, checkSigs, substitute));
co_return result::success();
} catch (...) {
return {result::current_exception()};
co_return result::current_exception();
}
std::optional<ValidPathInfo> decodeValidPathInfo(const Store & store, std::istream & str, std::optional<HashResult> hashGiven)
+2 -2
View File
@@ -921,14 +921,14 @@ void copyStorePath(
*
* @return a map of what each path was copied to the dstStore as.
*/
std::map<StorePath, StorePath> copyPaths(
kj::Promise<Result<std::map<StorePath, StorePath>>> copyPaths(
Store & srcStore, Store & dstStore,
const RealisedPath::Set &,
RepairFlag repair = NoRepair,
CheckSigsFlag checkSigs = CheckSigs,
SubstituteFlag substitute = NoSubstitute);
std::map<StorePath, StorePath> copyPaths(
kj::Promise<Result<std::map<StorePath, StorePath>>> copyPaths(
Store & srcStore, Store & dstStore,
const StorePathSet & paths,
RepairFlag repair = NoRepair,
+2 -2
View File
@@ -54,8 +54,8 @@ struct CmdCopy : virtual CopyCommand, BuiltPathsCommand
stuffToCopy.insert(theseRealisations.begin(), theseRealisations.end());
}
copyPaths(
*srcStore, *dstStore, stuffToCopy, NoRepair, checkSigs, substitute);
aio().blockOn(copyPaths(
*srcStore, *dstStore, stuffToCopy, NoRepair, checkSigs, substitute));
}
};
+1 -1
View File
@@ -1097,7 +1097,7 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun
if (!dryRun && !dstUri.empty()) {
ref<Store> dstStore = aio().blockOn(dstUri.empty() ? openStore() : openStore(dstUri));
copyPaths(*store, *dstStore, sources);
aio().blockOn(copyPaths(*store, *dstStore, sources));
}
}
};