diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index c36a3f130..808d3b6ac 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -265,10 +265,14 @@ kj::Promise>> RemoteStore::queryPathInfoUncached(const StorePath & path) try { auto conn(TRY_AWAIT(getConnection())); + std::optional pathInfo; try { - auto valid = - TRY_AWAIT(conn.sendCommand(WorkerProto::Op::QueryPathInfo, printStorePath(path))); - if (!valid) co_return result::success(nullptr); + pathInfo = TRY_AWAIT(conn.sendCommand>( + WorkerProto::Op::QueryPathInfo, printStorePath(path) + )); + if (!pathInfo) { + co_return result::success(nullptr); + } } catch (Error & e) { // Ugly backwards compatibility hack. TODO(fj#325): remove. if (e.msg().find("is not valid") != std::string::npos) @@ -276,9 +280,7 @@ try { throw; } - co_return std::make_shared( - StorePath{path}, - WorkerProto::Serialise::read(*conn)); + co_return std::make_shared(StorePath{path}, std::move(*pathInfo)); } catch (...) { co_return result::current_exception(); } @@ -288,9 +290,9 @@ kj::Promise> RemoteStore::queryReferrers(const StorePath & path, StorePathSet & referrers) try { auto conn(TRY_AWAIT(getConnection())); - TRY_AWAIT(conn.sendCommand(WorkerProto::Op::QueryReferrers, printStorePath(path))); - for (auto & i : WorkerProto::Serialise::read(*conn)) - referrers.insert(i); + referrers.merge(TRY_AWAIT( + conn.sendCommand(WorkerProto::Op::QueryReferrers, printStorePath(path)) + )); co_return result::success(); } catch (...) { co_return result::current_exception(); diff --git a/lix/libstore/worker-protocol.cc b/lix/libstore/worker-protocol.cc index d91384c2e..bbe5af805 100644 --- a/lix/libstore/worker-protocol.cc +++ b/lix/libstore/worker-protocol.cc @@ -6,6 +6,7 @@ #include "lix/libstore/worker-protocol-impl.hh" #include "lix/libutil/archive.hh" #include "lix/libstore/path-info.hh" +#include namespace nix { @@ -152,6 +153,27 @@ WireFormatGenerator WorkerProto::Serialise::write(WriteCon co_yield renderContentAddress(pathInfo.ca); } +std::optional +WorkerProto::Serialise>::read(ReadConn conn) +{ + bool valid; + conn.from >> valid; + if (valid) { + return WorkerProto::Serialise::read(conn); + } else { + return std::nullopt; + } +} + +WireFormatGenerator WorkerProto::Serialise>::write( + WriteConn conn, const std::optional & pathInfo +) +{ + co_yield pathInfo.has_value(); + if (pathInfo.has_value()) { + co_yield WorkerProto::write(conn, *pathInfo); + } +} SubstitutablePathInfo WorkerProto::Serialise::read(ReadConn conn) { diff --git a/lix/libstore/worker-protocol.hh b/lix/libstore/worker-protocol.hh index 8b7624feb..84e17e54e 100644 --- a/lix/libstore/worker-protocol.hh +++ b/lix/libstore/worker-protocol.hh @@ -239,6 +239,8 @@ DECLARE_WORKER_SERIALISER(UnkeyedValidPathInfo); template<> DECLARE_WORKER_SERIALISER(std::optional); template<> +DECLARE_WORKER_SERIALISER(std::optional); +template<> DECLARE_WORKER_SERIALISER(SubstitutablePathInfo); template