From dd31a23c31c8a686e0c18499b615e22a43932350 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 6 Jun 2025 18:09:46 +0200 Subject: [PATCH] libstore: add worker serializer for SubstitutablePathInfo the test is for the map that usually wraps it though because it's the bit we're interested in replacing, and it has custom serializer code. Change-Id: If77a236dfca738b646ed2b7a5c65515dad6b7295 --- lix/libstore/daemon.cc | 8 +---- lix/libstore/path-info.hh | 3 ++ lix/libstore/remote-store.cc | 13 ++----- lix/libstore/worker-protocol.cc | 21 +++++++++++ lix/libstore/worker-protocol.hh | 3 ++ .../substitutable-path-infos.bin | Bin 0 -> 296 bytes tests/unit/libstore/worker-protocol.cc | 33 ++++++++++++++++++ 7 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 tests/unit/libstore/data/libstore/worker-protocol/substitutable-path-infos.bin diff --git a/lix/libstore/daemon.cc b/lix/libstore/daemon.cc index 8362aca7c..c32857e9d 100644 --- a/lix/libstore/daemon.cc +++ b/lix/libstore/daemon.cc @@ -682,13 +682,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store logger->startWork(); aio.blockOn(store->querySubstitutablePathInfos(pathsMap, infos)); logger->stopWork(); - to << infos.size(); - for (auto & i : infos) { - to << store->printStorePath(i.first) - << (i.second.deriver ? store->printStorePath(*i.second.deriver) : ""); - to << WorkerProto::write(*store, wconn, i.second.references); - to << i.second.downloadSize << i.second.narSize; - } + to << WorkerProto::write(*store, wconn, infos); break; } diff --git a/lix/libstore/path-info.hh b/lix/libstore/path-info.hh index ad022e752..9fc76027b 100644 --- a/lix/libstore/path-info.hh +++ b/lix/libstore/path-info.hh @@ -27,6 +27,9 @@ struct SubstitutablePathInfo * 0 = unknown */ uint64_t narSize; + + bool operator==(const SubstitutablePathInfo &) const = default; + bool operator!=(const SubstitutablePathInfo &) const = default; }; using SubstitutablePathInfos = std::map; diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 930cbd7a0..365729226 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -23,6 +23,7 @@ #include "lix/libutil/thread-name.hh" #include "lix/libutil/thread-pool.hh" #include "lix/libutil/types.hh" +#include "path-info.hh" #include #include @@ -240,17 +241,7 @@ try { conn->to << WorkerProto::Op::QuerySubstitutablePathInfos; conn->to << WorkerProto::write(*this, *conn, pathsMap); conn.processStderr(); - size_t count = readNum(conn->from); - for (size_t n = 0; n < count; n++) { - SubstitutablePathInfo & info(infos[parseStorePath(readString(conn->from))]); - auto deriver = readString(conn->from); - if (deriver != "") - info.deriver = parseStorePath(deriver); - info.references = WorkerProto::Serialise::read(*this, *conn); - info.downloadSize = readLongLong(conn->from); - info.narSize = readLongLong(conn->from); - } - + infos = WorkerProto::Serialise::read(*this, *conn); 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 d2226eb39..71adfe6f8 100644 --- a/lix/libstore/worker-protocol.cc +++ b/lix/libstore/worker-protocol.cc @@ -152,4 +152,25 @@ WireFormatGenerator WorkerProto::Serialise::write(const St co_yield renderContentAddress(pathInfo.ca); } + +SubstitutablePathInfo WorkerProto::Serialise::read(const Store & store, ReadConn conn) +{ + SubstitutablePathInfo info; + auto deriver = readString(conn.from); + if (deriver != "") + info.deriver = store.parseStorePath(deriver); + info.references = WorkerProto::Serialise::read(store, conn); + info.downloadSize = readLongLong(conn.from); + info.narSize = readLongLong(conn.from); + return info; +} + +WireFormatGenerator WorkerProto::Serialise::write(const Store & store, WriteConn conn, const SubstitutablePathInfo & info) +{ + co_yield (info.deriver ? store.printStorePath(*info.deriver) : ""); + co_yield WorkerProto::write(store, conn, info.references); + co_yield info.downloadSize; + co_yield info.narSize; +} + } diff --git a/lix/libstore/worker-protocol.hh b/lix/libstore/worker-protocol.hh index 1c6c12aed..968082523 100644 --- a/lix/libstore/worker-protocol.hh +++ b/lix/libstore/worker-protocol.hh @@ -2,6 +2,7 @@ ///@file #include "lix/libstore/common-protocol.hh" +#include "path-info.hh" namespace nix { @@ -230,6 +231,8 @@ template<> DECLARE_WORKER_SERIALISER(UnkeyedValidPathInfo); template<> DECLARE_WORKER_SERIALISER(std::optional); +template<> +DECLARE_WORKER_SERIALISER(SubstitutablePathInfo); template DECLARE_WORKER_SERIALISER(std::vector); diff --git a/tests/unit/libstore/data/libstore/worker-protocol/substitutable-path-infos.bin b/tests/unit/libstore/data/libstore/worker-protocol/substitutable-path-infos.bin new file mode 100644 index 0000000000000000000000000000000000000000..658f17dad7221d5f19df0d6806110943bd2e7500 GIT binary patch literal 296 zcmZQ#fB=0MotIgmUtE%3l&YU@SZ #include "lix/libstore/worker-protocol.hh" +#include "lix/libstore/path-info.hh" #include "lix/libstore/worker-protocol-impl.hh" #include "lix/libstore/derived-path.hh" #include "lix/libstore/build-result.hh" @@ -283,4 +284,36 @@ VERSIONED_CHARACTERIZATION_TEST( }, })) +VERSIONED_CHARACTERIZATION_TEST( + WorkerProtoTest, + substitutablePathInfos, + "substitutable-path-infos", + defaultVersion, + (SubstitutablePathInfos{ + {StorePath{ + "g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-foo", + }, + SubstitutablePathInfo{ + std::nullopt, + {}, + 123456789, + 987654321, + }}, + {StorePath{ + "g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-bar", + }, + SubstitutablePathInfo{ + StorePath{ + "g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-fox", + }, + { + StorePath{ + "g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-other", + }, + }, + 987654321, + 123456789, + }}, + }) +) }