From e19a1a25e8d2335f8342d6e05d9b730ffd5951b9 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 9 Feb 2025 17:30:04 +0100 Subject: [PATCH] libstore: asyncify Store::getBuildDerivationPath Change-Id: Ie9c41eab4bfa548aa19f6587d60d9c0250ef2f54 --- lix/libstore/log-store.cc | 2 +- lix/libstore/store-api.cc | 16 +++++++++------- lix/libstore/store-api.hh | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lix/libstore/log-store.cc b/lix/libstore/log-store.cc index 5911c84d5..eeb07d737 100644 --- a/lix/libstore/log-store.cc +++ b/lix/libstore/log-store.cc @@ -4,7 +4,7 @@ namespace nix { kj::Promise>> LogStore::getBuildLog(const StorePath & path) try { - auto maybePath = getBuildDerivationPath(path); + auto maybePath = TRY_AWAIT(getBuildDerivationPath(path)); if (!maybePath) co_return std::nullopt; co_return getBuildLogExact(maybePath.value()); diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index c36a94e8f..4fda8d4ac 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -1412,20 +1412,20 @@ Derivation readDerivationCommon(Store& store, const StorePath& drvPath, bool req } } -std::optional Store::getBuildDerivationPath(const StorePath & path) -{ +kj::Promise>> Store::getBuildDerivationPath(const StorePath & path) +try { if (!path.isDerivation()) { try { auto info = queryPathInfo(path); - return info->deriver; + co_return info->deriver; } catch (InvalidPath &) { - return std::nullopt; + co_return std::nullopt; } } if (!experimentalFeatureSettings.isEnabled(Xp::CaDerivations) || !isValidPath(path)) - return path; + co_return path; auto drv = readDerivation(path); if (!drv.type().hasKnownOutputPaths()) { @@ -1433,10 +1433,12 @@ std::optional Store::getBuildDerivationPath(const StorePath & path) // resolved derivation, so we need to get it first auto resolvedDrv = drv.tryResolve(*this); if (resolvedDrv) - return writeDerivation(*this, *resolvedDrv, NoRepair, true); + co_return writeDerivation(*this, *resolvedDrv, NoRepair, true); } - return path; + co_return path; +} catch (...) { + co_return result::current_exception(); } Derivation Store::readDerivation(const StorePath & drvPath) diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index f5399c2d8..bf82ba8c1 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -831,7 +831,7 @@ public: * - If the path is a content-addressed derivation, try to resolve it * - Otherwise, find one of its derivers */ - std::optional getBuildDerivationPath(const StorePath &); + kj::Promise>> getBuildDerivationPath(const StorePath &); /** * Hack to allow long-running processes like hydra-queue-runner to