Skip to content

Commit aac2270

Browse files
committed
Move ValidPathInfo serialization code to worker-protocol.{cc.hh}
It does not belong with the data type itself. This also materializes the fact that `copyPath` does not do any version negotiation just just hard-codes "16".
1 parent 7d0e16f commit aac2270

File tree

7 files changed

+69
-66
lines changed

7 files changed

+69
-66
lines changed

src/libstore/daemon.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
429429
}();
430430
logger->stopWork();
431431

432-
pathInfo->write(to, *store, GET_PROTOCOL_MINOR(clientVersion));
432+
worker_proto::write(*store, wconn, *pathInfo);
433433
} else {
434434
HashType hashAlgo;
435435
std::string baseName;
@@ -832,7 +832,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
832832
if (info) {
833833
if (GET_PROTOCOL_MINOR(clientVersion) >= 17)
834834
to << 1;
835-
info->write(to, *store, GET_PROTOCOL_MINOR(clientVersion), false);
835+
worker_proto::write(*store, wconn, *info, false);
836836
} else {
837837
assert(GET_PROTOCOL_MINOR(clientVersion) >= 17);
838838
to << 0;

src/libstore/path-info.cc

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include "path-info.hh"
2-
#include "worker-protocol.hh"
3-
#include "worker-protocol-impl.hh"
42
#include "store-api.hh"
53

64
namespace nix {
@@ -78,56 +76,4 @@ Strings ValidPathInfo::shortRefs() const
7876
return refs;
7977
}
8078

81-
82-
ValidPathInfo ValidPathInfo::read(Source & source, const Store & store, unsigned int format)
83-
{
84-
return read(source, store, format, store.parseStorePath(readString(source)));
85-
}
86-
87-
ValidPathInfo ValidPathInfo::read(Source & source, const Store & store, unsigned int format, StorePath && path)
88-
{
89-
auto deriver = readString(source);
90-
auto narHash = Hash::parseAny(readString(source), htSHA256);
91-
ValidPathInfo info(path, narHash);
92-
if (deriver != "") info.deriver = store.parseStorePath(deriver);
93-
info.references = worker_proto::read(store,
94-
worker_proto::ReadConn {
95-
{ .from = source },
96-
/* .version = */ format,
97-
},
98-
Phantom<StorePathSet> {});
99-
source >> info.registrationTime >> info.narSize;
100-
if (format >= 16) {
101-
source >> info.ultimate;
102-
info.sigs = readStrings<StringSet>(source);
103-
info.ca = parseContentAddressOpt(readString(source));
104-
}
105-
return info;
106-
}
107-
108-
109-
void ValidPathInfo::write(
110-
Sink & sink,
111-
const Store & store,
112-
unsigned int format,
113-
bool includePath) const
114-
{
115-
if (includePath)
116-
sink << store.printStorePath(path);
117-
sink << (deriver ? store.printStorePath(*deriver) : "")
118-
<< narHash.to_string(Base16, false);
119-
worker_proto::write(store,
120-
worker_proto::WriteConn {
121-
{ .to = sink },
122-
/* .version = */ format,
123-
},
124-
references);
125-
sink << registrationTime << narSize;
126-
if (format >= 16) {
127-
sink << ultimate
128-
<< sigs
129-
<< renderContentAddress(ca);
130-
}
131-
}
132-
13379
}

src/libstore/path-info.hh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ struct ValidPathInfo
9999
ValidPathInfo(const StorePath & path, Hash narHash) : path(path), narHash(narHash) { };
100100

101101
virtual ~ValidPathInfo() { }
102-
103-
static ValidPathInfo read(Source & source, const Store & store, unsigned int format);
104-
static ValidPathInfo read(Source & source, const Store & store, unsigned int format, StorePath && path);
105-
106-
void write(Sink & sink, const Store & store, unsigned int format, bool includePath = true) const;
107102
};
108103

109104
typedef std::map<StorePath, ValidPathInfo> ValidPathInfos;

src/libstore/remote-store.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path,
332332
if (!valid) throw InvalidPath("path '%s' is not valid", printStorePath(path));
333333
}
334334
info = std::make_shared<ValidPathInfo>(
335-
ValidPathInfo::read(conn->from, *this, GET_PROTOCOL_MINOR(conn->daemonVersion), StorePath{path}));
335+
worker_proto::readValidPathInfo(*this, *conn, StorePath{path}));
336336
}
337337
callback(std::move(info));
338338
} catch (...) { callback.rethrow(); }
@@ -435,7 +435,7 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
435435
}
436436

437437
return make_ref<ValidPathInfo>(
438-
ValidPathInfo::read(conn->from, *this, GET_PROTOCOL_MINOR(conn->daemonVersion)));
438+
worker_proto::readValidPathInfo(*this, *conn));
439439
}
440440
else {
441441
if (repair) throw Error("repairing is not supported when building through the Nix daemon protocol < 1.25");
@@ -557,7 +557,12 @@ void RemoteStore::addMultipleToStore(
557557
auto source = sinkToSource([&](Sink & sink) {
558558
sink << pathsToCopy.size();
559559
for (auto & [pathInfo, pathSource] : pathsToCopy) {
560-
pathInfo.write(sink, *this, 16);
560+
worker_proto::write(*this,
561+
worker_proto::WriteConn {
562+
{ .to = sink },
563+
/* .version = */ 16,
564+
},
565+
pathInfo);
561566
pathSource->drainInto(sink);
562567
}
563568
});

src/libstore/store-api.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "archive.hh"
1111
#include "callback.hh"
1212
#include "remote-store.hh"
13+
// FIXME this should not be here
14+
#include "worker-protocol.hh"
1315

1416
#include <nlohmann/json.hpp>
1517
#include <regex>
@@ -346,7 +348,11 @@ void Store::addMultipleToStore(
346348
{
347349
auto expected = readNum<uint64_t>(source);
348350
for (uint64_t i = 0; i < expected; ++i) {
349-
auto info = ValidPathInfo::read(source, *this, 16);
351+
auto info = worker_proto::readValidPathInfo(*this,
352+
worker_proto::ReadConn {
353+
{ .from = source },
354+
/* .version = */ 16,
355+
});
350356
info.ultimate = false;
351357
addToStore(info, source, repair, checkSigs);
352358
}

src/libstore/worker-protocol.cc

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "worker-protocol.hh"
77
#include "worker-protocol-impl.hh"
88
#include "archive.hh"
9-
#include "derivations.hh"
9+
#include "path-info.hh"
1010

1111
#include <nlohmann/json.hpp>
1212

@@ -44,5 +44,48 @@ void write(const Store & store, WriteConn conn, const BuildResult & res)
4444
}
4545

4646

47+
ValidPathInfo readValidPathInfo(const Store & store, ReadConn conn)
48+
{
49+
auto path = read(store, conn, Phantom<StorePath>{});
50+
return readValidPathInfo(store, conn, std::move(path));
51+
}
52+
53+
ValidPathInfo readValidPathInfo(const Store & store, ReadConn conn, StorePath && path)
54+
{
55+
auto deriver = readString(conn.from);
56+
auto narHash = Hash::parseAny(readString(conn.from), htSHA256);
57+
ValidPathInfo info(path, narHash);
58+
if (deriver != "") info.deriver = store.parseStorePath(deriver);
59+
info.references = read(store, conn, Phantom<StorePathSet> {});
60+
conn.from >> info.registrationTime >> info.narSize;
61+
if (GET_PROTOCOL_MINOR(conn.version) >= 16) {
62+
conn.from >> info.ultimate;
63+
info.sigs = readStrings<StringSet>(conn.from);
64+
info.ca = parseContentAddressOpt(readString(conn.from));
65+
}
66+
return info;
67+
}
68+
69+
void write(
70+
const Store & store,
71+
WriteConn conn,
72+
const ValidPathInfo & pathInfo,
73+
bool includePath)
74+
{
75+
if (includePath)
76+
conn.to << store.printStorePath(pathInfo.path);
77+
conn.to
78+
<< (pathInfo.deriver ? store.printStorePath(*pathInfo.deriver) : "")
79+
<< pathInfo.narHash.to_string(Base16, false);
80+
write(store, conn, pathInfo.references);
81+
conn.to << pathInfo.registrationTime << pathInfo.narSize;
82+
if (GET_PROTOCOL_MINOR(conn.version) >= 16) {
83+
conn.to
84+
<< pathInfo.ultimate
85+
<< pathInfo.sigs
86+
<< renderContentAddress(pathInfo.ca);
87+
}
88+
}
89+
4790
}
4891
}

src/libstore/worker-protocol.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct Source;
7575

7676
// items being serialized
7777
struct BuildResult;
78+
struct PathInfo;
7879

7980

8081
namespace worker_proto {
@@ -103,6 +104,13 @@ MAKE_PROTO(X_, Y_);
103104
#undef X_
104105
#undef Y_
105106

107+
/* These are a non-standard form for historical reasons. */
108+
109+
ValidPathInfo readValidPathInfo(const Store & store, ReadConn conn);
110+
ValidPathInfo readValidPathInfo(const Store & store, ReadConn conn, StorePath && path);
111+
112+
void write(const Store & store, WriteConn conn, const ValidPathInfo & pathInfo, bool includePath = true);
113+
106114
}
107115

108116
}

0 commit comments

Comments
 (0)