From e85242d6da2c3adbdfd2a616520c260162cd4edc Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 6 Feb 2025 23:59:27 +0100 Subject: [PATCH] libstore: asyncify Store::importPaths Change-Id: Ic330b9213209fd7d3cccf90af7f3d6b41aede9b5 --- lix/legacy/nix-store.cc | 4 ++-- lix/libstore/export-import.cc | 8 +++++--- lix/libstore/store-api.hh | 3 ++- perl/lib/Nix/Store.xs | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index 742a2db0b..6f3b0a07e 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -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; } diff --git a/lix/libstore/export-import.cc b/lix/libstore/export-import.cc index a0caeff2e..39e666a6d 100644 --- a/lix/libstore/export-import.cc +++ b/lix/libstore/export-import.cc @@ -49,8 +49,8 @@ void Store::exportPath(const StorePath & path, Sink & sink) << 0; } -StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs) -{ +kj::Promise> Store::importPaths(Source & source, CheckSigsFlag checkSigs) +try { StorePaths res; while (true) { auto n = readNum(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(); } } diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 8d449f62e..db4411757 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -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> + importPaths(Source & source, CheckSigsFlag checkSigs = CheckSigs); struct Stats { diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs index 1ce939f91..20875e019 100644 --- a/perl/lib/Nix/Store.xs +++ b/perl/lib/Nix/Store.xs @@ -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()); }