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 000000000..658f17dad Binary files /dev/null and b/tests/unit/libstore/data/libstore/worker-protocol/substitutable-path-infos.bin differ diff --git a/tests/unit/libstore/worker-protocol.cc b/tests/unit/libstore/worker-protocol.cc index 0bc32ce69..e4c7ef500 100644 --- a/tests/unit/libstore/worker-protocol.cc +++ b/tests/unit/libstore/worker-protocol.cc @@ -3,6 +3,7 @@ #include #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, + }}, + }) +) }