From a783d2c0d9ca3d72e2afa515cec7f616b5108f2e Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 5 Mar 2025 16:42:11 +0100 Subject: [PATCH] libstore: asyncify Store::connect Change-Id: I6668295e228092754304ef63cda0b889bd82b198 --- lix/legacy/build-remote.cc | 2 +- lix/libstore/legacy-ssh-store.cc | 7 +++++-- lix/libstore/remote-store.cc | 7 +++++-- lix/libstore/remote-store.hh | 2 +- lix/libstore/store-api.hh | 2 +- lix/nix/ping-store.cc | 4 ++-- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lix/legacy/build-remote.cc b/lix/legacy/build-remote.cc index 091b8fe41..ced54fd88 100644 --- a/lix/legacy/build-remote.cc +++ b/lix/legacy/build-remote.cc @@ -244,7 +244,7 @@ static int main_build_remote(AsyncIoRoot & aio, std::string programName, Strings Activity act(*logger, lvlTalkative, actUnknown, fmt("connecting to '%s'", bestMachine->storeUri)); sshStore = aio.blockOn(bestMachine->openStore()); - sshStore->connect(); + aio.blockOn(sshStore->connect()); storeUri = bestMachine->storeUri; } catch (std::exception & e) { diff --git a/lix/libstore/legacy-ssh-store.cc b/lix/libstore/legacy-ssh-store.cc index 5d97a7185..311d346a4 100644 --- a/lix/libstore/legacy-ssh-store.cc +++ b/lix/libstore/legacy-ssh-store.cc @@ -431,9 +431,12 @@ public: co_return result::current_exception(); } - void connect() override - { + kj::Promise> connect() override + try { auto conn(connections->get()); + co_return result::success(); + } catch (...) { + co_return result::current_exception(); } unsigned int getProtocol() override diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index f34332376..0d314857a 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -935,9 +935,12 @@ std::optional RemoteStore::getVersion() } -void RemoteStore::connect() -{ +kj::Promise> RemoteStore::connect() +try { auto conn(getConnection()); + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/remote-store.hh b/lix/libstore/remote-store.hh index 60a23adb3..a0d9f6bb4 100644 --- a/lix/libstore/remote-store.hh +++ b/lix/libstore/remote-store.hh @@ -165,7 +165,7 @@ public: std::optional getVersion() override; - void connect() override; + kj::Promise> connect() override; unsigned int getProtocol() override; diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 92e92601c..87110d360 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -862,7 +862,7 @@ public: * Establish a connection to the store, for store types that have * a notion of connection. Otherwise this is a no-op. */ - virtual void connect() { }; + virtual kj::Promise> connect() { return {result::success()}; } /** * Get the protocol version of this store or it's connection. diff --git a/lix/nix/ping-store.cc b/lix/nix/ping-store.cc index 7232874a6..e0a029327 100644 --- a/lix/nix/ping-store.cc +++ b/lix/nix/ping-store.cc @@ -25,7 +25,7 @@ struct CmdPingStore : StoreCommand, MixJSON { if (!json) { notice("Store URL: %s", store->getUri()); - store->connect(); + aio().blockOn(store->connect()); if (auto version = store->getVersion()) notice("Version: %s", *version); if (auto trusted = store->isTrustedClient()) @@ -37,7 +37,7 @@ struct CmdPingStore : StoreCommand, MixJSON }); res["url"] = store->getUri(); - store->connect(); + aio().blockOn(store->connect()); if (auto version = store->getVersion()) res["version"] = *version; if (auto trusted = store->isTrustedClient())