From 12e9b8da0fb6f83b2fb62a5e26f14570a734ea83 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 5 Mar 2025 16:42:11 +0100 Subject: [PATCH] libstore: asyncify Store::getProtocol Change-Id: I52744d925d1239fd326a3ec4e3a26e8e8ca44be0 --- lix/libstore/legacy-ssh-store.cc | 8 +++++--- lix/libstore/local-store.cc | 4 ++-- lix/libstore/local-store.hh | 2 +- lix/libstore/remote-store.cc | 14 ++++++++------ lix/libstore/remote-store.hh | 2 +- lix/libstore/store-api.hh | 4 ++-- lix/nix/doctor.cc | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lix/libstore/legacy-ssh-store.cc b/lix/libstore/legacy-ssh-store.cc index 311d346a4..4bb67595f 100644 --- a/lix/libstore/legacy-ssh-store.cc +++ b/lix/libstore/legacy-ssh-store.cc @@ -439,10 +439,12 @@ public: co_return result::current_exception(); } - unsigned int getProtocol() override - { + kj::Promise> getProtocol() override + try { auto conn(connections->get()); - return conn->remoteVersion; + co_return conn->remoteVersion; + } catch (...) { + co_return result::current_exception(); } /** diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index 7d6044d43..c51677a23 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -1740,9 +1740,9 @@ try { } -unsigned int LocalStore::getProtocol() +kj::Promise> LocalStore::getProtocol() { - return PROTOCOL_VERSION; + return {result::success(PROTOCOL_VERSION)}; } std::optional LocalStore::isTrustedClient() diff --git a/lix/libstore/local-store.hh b/lix/libstore/local-store.hh index 2e32f82cd..8b0963c70 100644 --- a/lix/libstore/local-store.hh +++ b/lix/libstore/local-store.hh @@ -298,7 +298,7 @@ public: void registerValidPaths(const ValidPathInfos & infos); - unsigned int getProtocol() override; + kj::Promise> getProtocol() override; std::optional isTrustedClient() override; diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 0d314857a..4e7c626e1 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -322,7 +322,7 @@ StorePathSet RemoteStore::queryValidDerivers(const StorePath & path) kj::Promise> RemoteStore::queryDerivationOutputs(const StorePath & path) try { - if (GET_PROTOCOL_MINOR(getProtocol()) >= 22) { + if (GET_PROTOCOL_MINOR(TRY_AWAIT(getProtocol())) >= 22) { co_return TRY_AWAIT(Store::queryDerivationOutputs(path)); } REMOVE_AFTER_DROPPING_PROTO_MINOR(21); @@ -338,7 +338,7 @@ try { kj ::Promise>>> RemoteStore::queryPartialDerivationOutputMap(const StorePath & path, Store * evalStore_) try { - if (GET_PROTOCOL_MINOR(getProtocol()) >= 22) { + if (GET_PROTOCOL_MINOR(TRY_AWAIT(getProtocol())) >= 22) { if (!evalStore_) { auto conn(getConnection()); conn->to << WorkerProto::Op::QueryDerivationOutputMap << printStorePath(path); @@ -551,7 +551,7 @@ kj::Promise> RemoteStore::addMultipleToStore( CheckSigsFlag checkSigs) try { if (GET_PROTOCOL_MINOR(getConnection()->daemonVersion) >= 32) { - auto remoteVersion = getProtocol(); + auto remoteVersion = TRY_AWAIT(getProtocol()); auto conn(getConnection()); conn->to @@ -944,10 +944,12 @@ try { } -unsigned int RemoteStore::getProtocol() -{ +kj::Promise> RemoteStore::getProtocol() +try { auto conn(connections->get()); - return conn->daemonVersion; + co_return conn->daemonVersion; +} catch (...) { + co_return result::current_exception(); } std::optional RemoteStore::isTrustedClient() diff --git a/lix/libstore/remote-store.hh b/lix/libstore/remote-store.hh index a0d9f6bb4..d73c9a280 100644 --- a/lix/libstore/remote-store.hh +++ b/lix/libstore/remote-store.hh @@ -167,7 +167,7 @@ public: kj::Promise> connect() override; - unsigned int getProtocol() override; + kj::Promise> getProtocol() override; std::optional isTrustedClient() override; diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 87110d360..650c812d2 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -867,9 +867,9 @@ public: /** * Get the protocol version of this store or it's connection. */ - virtual unsigned int getProtocol() + virtual kj::Promise> getProtocol() { - return 0; + return {result::success(0)}; }; /** diff --git a/lix/nix/doctor.cc b/lix/nix/doctor.cc index 635fd3891..c7f9d0715 100644 --- a/lix/nix/doctor.cc +++ b/lix/nix/doctor.cc @@ -66,7 +66,7 @@ struct CmdDoctor : StoreCommand success &= checkNixInPath(); success &= checkProfileRoots(store); } - success &= checkStoreProtocol(store->getProtocol()); + success &= checkStoreProtocol(aio().blockOn(store->getProtocol())); checkTrustedUser(store); if (!success)