libstore: asyncify Store::importPaths

Change-Id: Ic330b9213209fd7d3cccf90af7f3d6b41aede9b5
This commit is contained in:
eldritch horrors
2025-02-08 17:26:19 +00:00
parent 70026b1696
commit e85242d6da
4 changed files with 10 additions and 7 deletions
+2 -2
View File
@@ -716,7 +716,7 @@ static void opImport(AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
if (!opArgs.empty()) throw UsageError("no arguments expected");
FdSource source(STDIN_FILENO);
auto paths = store->importPaths(source, NoCheckSigs);
auto paths = aio.blockOn(store->importPaths(source, NoCheckSigs));
for (auto & i : paths)
cout << fmt("%s\n", store->printStorePath(i)) << std::flush;
@@ -910,7 +910,7 @@ static void opServe(AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
case ServeProto::Command::ImportPaths: {
if (!writeAllowed) throw Error("importing paths is not allowed");
store->importPaths(in, NoCheckSigs); // FIXME: should we skip sig checking?
aio.blockOn(store->importPaths(in, NoCheckSigs)); // FIXME: should we skip sig checking?
out << 1; // indicate success
break;
}
+5 -3
View File
@@ -49,8 +49,8 @@ void Store::exportPath(const StorePath & path, Sink & sink)
<< 0;
}
StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
{
kj::Promise<Result<StorePaths>> Store::importPaths(Source & source, CheckSigsFlag checkSigs)
try {
StorePaths res;
while (true) {
auto n = readNum<uint64_t>(source);
@@ -91,7 +91,9 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
res.push_back(info.path);
}
return res;
co_return res;
} catch (...) {
co_return result::current_exception();
}
}
+2 -1
View File
@@ -796,7 +796,8 @@ public:
* Nix store. Optionally, the contents of the NARs are preloaded
* into the specified FS accessor to speed up subsequent access.
*/
StorePaths importPaths(Source & source, CheckSigsFlag checkSigs = CheckSigs);
kj::Promise<Result<StorePaths>>
importPaths(Source & source, CheckSigsFlag checkSigs = CheckSigs);
struct Stats
{
+1 -1
View File
@@ -207,7 +207,7 @@ void importPaths(int fd, int dontCheckSigs)
PPCODE:
try {
FdSource source(fd);
store()->importPaths(source, dontCheckSigs ? NoCheckSigs : CheckSigs);
aio().blockOn(store()->importPaths(source, dontCheckSigs ? NoCheckSigs : CheckSigs));
} catch (Error & e) {
croak("%s", e.what());
}