libstore: asyncify makeContentAddressed

Change-Id: I3cdad058a9f015983db5306271c56a9996aaef28
This commit is contained in:
eldritch horrors
2025-02-08 13:50:33 +00:00
parent 5fd2d24e63
commit b60314f32e
4 changed files with 18 additions and 12 deletions
+2 -1
View File
@@ -20,7 +20,8 @@ static void runFetchClosureWithRewrite(EvalState & state, const PosIdx pos, Stor
// establish toPath or throw
if (!toPathMaybe || !state.ctx.store->isValidPath(*toPathMaybe)) {
auto rewrittenPath = makeContentAddressed(fromStore, *state.ctx.store, fromPath);
auto rewrittenPath =
state.aio.blockOn(makeContentAddressed(fromStore, *state.ctx.store, fromPath));
if (toPathMaybe && *toPathMaybe != rewrittenPath)
throw Error({
.msg = HintFmt("rewriting '%s' to content-addressed form yielded '%s', while '%s' was expected",
+12 -7
View File
@@ -1,14 +1,15 @@
#include "lix/libstore/make-content-addressed.hh"
#include "lix/libutil/async.hh"
#include "lix/libutil/references.hh"
#include "lix/libutil/strings.hh"
namespace nix {
std::map<StorePath, StorePath> makeContentAddressed(
kj::Promise<Result<std::map<StorePath, StorePath>>> makeContentAddressed(
Store & srcStore,
Store & dstStore,
const StorePathSet & storePaths)
{
try {
StorePathSet closure;
srcStore.computeFSClosure(storePaths, closure);
@@ -73,18 +74,22 @@ std::map<StorePath, StorePath> makeContentAddressed(
remappings.insert_or_assign(std::move(path), std::move(info.path));
}
return remappings;
co_return remappings;
} catch (...) {
co_return result::current_exception();
}
StorePath makeContentAddressed(
kj::Promise<Result<StorePath>> makeContentAddressed(
Store & srcStore,
Store & dstStore,
const StorePath & fromPath)
{
auto remappings = makeContentAddressed(srcStore, dstStore, StorePathSet { fromPath });
try {
auto remappings = TRY_AWAIT(makeContentAddressed(srcStore, dstStore, StorePathSet{fromPath}));
auto i = remappings.find(fromPath);
assert(i != remappings.end());
return i->second;
co_return i->second;
} catch (...) {
co_return result::current_exception();
}
}
+2 -2
View File
@@ -7,7 +7,7 @@ namespace nix {
/** Rewrite a closure of store paths to be completely content addressed.
*/
std::map<StorePath, StorePath> makeContentAddressed(
kj::Promise<Result<std::map<StorePath, StorePath>>> makeContentAddressed(
Store & srcStore,
Store & dstStore,
const StorePathSet & rootPaths);
@@ -16,7 +16,7 @@ std::map<StorePath, StorePath> makeContentAddressed(
*
* This is a convenience function for the case where you only have one root path.
*/
StorePath makeContentAddressed(
kj::Promise<Result<StorePath>> makeContentAddressed(
Store & srcStore,
Store & dstStore,
const StorePath & rootPath);
+2 -2
View File
@@ -32,8 +32,8 @@ struct CmdMakeContentAddressed : virtual CopyCommand, virtual StorePathsCommand,
{
auto dstStore = aio().blockOn(dstUri.empty() ? openStore() : openStore(dstUri));
auto remappings = makeContentAddressed(*srcStore, *dstStore,
StorePathSet(storePaths.begin(), storePaths.end()));
auto remappings = aio().blockOn(makeContentAddressed(*srcStore, *dstStore,
StorePathSet(storePaths.begin(), storePaths.end())));
if (json) {
auto jsonRewrites = json::object();