libstore: asyncify Store::exportPath{,s}

Change-Id: I92915a3cb27bda73e7b9f3b32dc1feea3f47abda
This commit is contained in:
eldritch horrors
2025-02-22 23:24:26 +00:00
parent a2e523aa8b
commit 8fc0e0d24b
4 changed files with 19 additions and 10 deletions
+4 -2
View File
@@ -713,7 +713,7 @@ static void opExport(AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
paths.insert(store->followLinksToStorePath(i));
FdSink sink(STDOUT_FILENO);
store->exportPaths(paths, sink);
aio.blockOn(store->exportPaths(paths, sink));
sink.flush();
}
@@ -927,7 +927,9 @@ static void opServe(AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
case ServeProto::Command::ExportPaths: {
readInt(in); // obsolete
store->exportPaths(ServeProto::Serialise<StorePathSet>::read(*store, rconn), out);
aio.blockOn(store->exportPaths(
ServeProto::Serialise<StorePathSet>::read(*store, rconn), out
));
break;
}
+12 -5
View File
@@ -1,3 +1,4 @@
#include "lix/libutil/result.hh"
#include "lix/libutil/serialise.hh"
#include "lix/libstore/store-api.hh"
#include "lix/libutil/archive.hh"
@@ -8,21 +9,24 @@
namespace nix {
void Store::exportPaths(const StorePathSet & paths, Sink & sink)
{
kj::Promise<Result<void>> Store::exportPaths(const StorePathSet & paths, Sink & sink)
try {
auto sorted = topoSortPaths(paths);
std::reverse(sorted.begin(), sorted.end());
for (auto & path : sorted) {
sink << 1;
exportPath(path, sink);
TRY_AWAIT(exportPath(path, sink));
}
sink << 0;
co_return result::success();
} catch (...) {
co_return result::current_exception();
}
void Store::exportPath(const StorePath & path, Sink & sink)
{
kj::Promise<Result<void>> Store::exportPath(const StorePath & path, Sink & sink)
try {
auto info = queryPathInfo(path);
HashSink hashSink(HashType::SHA256);
@@ -47,6 +51,9 @@ void Store::exportPath(const StorePath & path, Sink & sink)
teeSink
<< (info->deriver ? printStorePath(*info->deriver) : "")
<< 0;
co_return result::success();
} catch (...) {
co_return result::current_exception();
}
kj::Promise<Result<StorePaths>> Store::importPaths(Source & source, CheckSigsFlag checkSigs)
+2 -2
View File
@@ -793,9 +793,9 @@ public:
* Export multiple paths in the format expected by nix-store
* --import.
*/
void exportPaths(const StorePathSet & paths, Sink & sink);
kj::Promise<Result<void>> exportPaths(const StorePathSet & paths, Sink & sink);
void exportPath(const StorePath & path, Sink & sink);
kj::Promise<Result<void>> exportPath(const StorePath & path, Sink & sink);
/**
* Import a sequence of NAR dumps created by exportPaths() into the
+1 -1
View File
@@ -197,7 +197,7 @@ void exportPaths(int fd, ...)
StorePathSet paths;
for (int n = 1; n < items; ++n) paths.insert(store()->parseStorePath(SvPV_nolen(ST(n))));
FdSink sink(fd);
store()->exportPaths(paths, sink);
aio().blockOn(store()->exportPaths(paths, sink));
} catch (Error & e) {
croak("%s", e.what());
}