libfetchers: asyncify fetchToStore

Change-Id: I0153cefbe974137ab3d4fd9218c8a77137976f8c
This commit is contained in:
eldritch horrors
2025-02-08 17:26:19 +00:00
parent 5a0c979afa
commit ed2d1080be
5 changed files with 22 additions and 11 deletions
+3 -1
View File
@@ -47,7 +47,9 @@ std::optional<DerivedPathWithInfo> InstallableValue::trySinglePathToDerivedPaths
)
{
if (v.type() == nPath) {
auto storePath = fetchToStore(*evaluator->store, state.ctx.paths.checkSourcePath(v.path()));
auto storePath = state.aio.blockOn(
fetchToStore(*evaluator->store, state.ctx.paths.checkSourcePath(v.path()))
);
return {{
.path = DerivedPath::Opaque {
.path = std::move(storePath),
+11 -4
View File
@@ -2366,13 +2366,20 @@ try {
auto dstPath = i != srcToStore.end()
? i->second
: [&]() {
auto dstPath = fetchToStore(*store, checkSourcePath(path), path.baseName(), FileIngestionMethod::Recursive, nullptr, repair);
: ({
auto dstPath = TRY_AWAIT(fetchToStore(
*store,
checkSourcePath(path),
path.baseName(),
FileIngestionMethod::Recursive,
nullptr,
repair
));
allowPath(dstPath);
srcToStore.insert_or_assign(path, dstPath);
printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath));
return dstPath;
}();
std::move(dstPath);
});
context.insert(NixStringContextElem::Opaque {
.path = dstPath
+2 -2
View File
@@ -1557,14 +1557,14 @@ static void addPath(
});
if (!expectedHash || !state.ctx.store->isValidPath(*expectedStorePath)) {
auto dstPath = fetchToStore(
auto dstPath = state.aio.blockOn(fetchToStore(
*state.ctx.store,
state.ctx.paths.checkSourcePath(CanonPath(path)),
name,
method,
&filter,
state.ctx.repair
);
));
if (expectedHash && expectedStorePath != dstPath)
state.ctx.errors.make<EvalError>(
"store path mismatch in (possibly filtered) path added from '%s'",
+5 -3
View File
@@ -4,22 +4,24 @@
namespace nix {
StorePath fetchToStore(
kj::Promise<Result<StorePath>> fetchToStore(
Store & store,
const CheckedSourcePath & path,
std::string_view name,
FileIngestionMethod method,
PathFilter * filter,
RepairFlag repair)
{
try {
Activity act(*logger, lvlChatty, actUnknown, fmt("copying '%s' to the store", path));
auto filter2 = filter ? *filter : defaultPathFilter;
return
co_return
settings.readOnlyMode
? store.computeStorePathForPath(name, path.canonical().abs(), method, HashType::SHA256, filter2).first
: store.addToStore(name, path.canonical().abs(), method, HashType::SHA256, filter2, repair);
} catch (...) {
co_return result::current_exception();
}
+1 -1
View File
@@ -11,7 +11,7 @@ namespace nix {
/**
* Copy the `path` to the Nix store.
*/
StorePath fetchToStore(
kj::Promise<Result<StorePath>> fetchToStore(
Store & store,
const CheckedSourcePath & path,
std::string_view name = "source",