From a51380645f61b33d37a536b596d16c481f7b84a6 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 31 Jan 2025 01:30:43 +0100 Subject: [PATCH] libstore: asyncify Store::substitutePaths Change-Id: I8cb6822ad9145fbcf0f98f32c121482c3a3db2a8 --- lix/legacy/nix-store.cc | 2 +- lix/libstore/daemon.cc | 2 +- lix/libstore/store-api.cc | 11 ++++++++--- lix/libstore/store-api.hh | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index 71018f3b7..2ac5dd72c 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -881,7 +881,7 @@ static void opServe(AsyncIoRoot & aio, Strings opFlags, Strings opArgs) store->addTempRoot(path); if (substitute && writeAllowed) { - store->substitutePaths(paths); + aio.blockOn(store->substitutePaths(paths)); } auto valid = store->queryValidPaths(paths); diff --git a/lix/libstore/daemon.cc b/lix/libstore/daemon.cc index 3b8d1e2df..00fc99ac3 100644 --- a/lix/libstore/daemon.cc +++ b/lix/libstore/daemon.cc @@ -289,7 +289,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store logger->startWork(); if (substitute) { - store->substitutePaths(paths); + aio.blockOn(store->substitutePaths(paths)); } auto res = store->queryValidPaths(paths, substitute); logger->stopWork(); diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index a937c2eb0..c97877331 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -4,6 +4,7 @@ #include "lix/libstore/store-api.hh" #include "lix/libstore/nar-info-disk-cache.hh" #include "lix/libutil/async.hh" +#include "lix/libutil/result.hh" #include "lix/libutil/thread-pool.hh" #include "lix/libutil/url.hh" #include "lix/libutil/archive.hh" @@ -801,8 +802,8 @@ std::shared_ptr Store::queryRealisation(const DrvOutput & id) return info; } -void Store::substitutePaths(const StorePathSet & paths) -{ +kj::Promise> Store::substitutePaths(const StorePathSet & paths) +try { std::vector paths2; for (auto & path : paths) if (!path.isDerivation()) @@ -816,10 +817,14 @@ void Store::substitutePaths(const StorePathSet & paths) try { std::vector subs; for (auto & p : willSubstitute) subs.emplace_back(DerivedPath::Opaque{p}); - RUN_ASYNC_IN_NEW_THREAD(buildPaths(subs)); + TRY_AWAIT(buildPaths(subs)); } catch (Error & e) { logWarning(e.info()); } + + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index ff53e8ffc..71ccf173d 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -354,7 +354,7 @@ public: * implements nix-copy-closure's --use-substitutes * flag. */ - void substitutePaths(const StorePathSet & paths); + kj::Promise> substitutePaths(const StorePathSet & paths); /** * Query which of the given paths is valid. Optionally, try to