Skip to content

Commit 38a26a1

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 7b14610 commit 38a26a1

File tree

7 files changed

+70
-70
lines changed

7 files changed

+70
-70
lines changed

src/libstore/daemon.cc

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

426-
pathInfo->write(to, *store, GET_PROTOCOL_MINOR(clientVersion));
426+
worker_proto::write(*store, wconn, *pathInfo);
427427
} else {
428428
HashType hashAlgo;
429429
std::string baseName;
@@ -817,7 +817,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
817817
if (info) {
818818
if (GET_PROTOCOL_MINOR(clientVersion) >= 17)
819819
to << 1;
820-
info->write(to, *store, GET_PROTOCOL_MINOR(clientVersion), false);
820+
worker_proto::write(*store, wconn, *info, false);
821821
} else {
822822
assert(GET_PROTOCOL_MINOR(clientVersion) >= 17);
823823
to << 0;

src/libstore/path-info.cc

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/libstore/path-info.hh

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

107107
virtual ~ValidPathInfo() { }
108-
109-
static ValidPathInfo read(Source & source, const Store & store, unsigned int format);
110-
static ValidPathInfo read(Source & source, const Store & store, unsigned int format, StorePath && path);
111-
112-
void write(Sink & sink, const Store & store, unsigned int format, bool includePath = true) const;
113108
};
114109

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

src/libstore/remote-store.cc

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

436436
return make_ref<ValidPathInfo>(
437-
ValidPathInfo::read(conn->from, *this, GET_PROTOCOL_MINOR(conn->daemonVersion)));
437+
worker_proto::readValidPathInfo(*this, *conn));
438438
}
439439
else {
440440
if (repair) throw Error("repairing is not supported when building through the Nix daemon protocol < 1.25");

src/libstore/store-api.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "archive.hh"
1212
#include "callback.hh"
1313
#include "remote-store.hh"
14+
// FIXME this should not be here
15+
#include "worker-protocol.hh"
1416

1517
#include <regex>
1618

@@ -266,7 +268,11 @@ void Store::addMultipleToStore(
266268
{
267269
auto expected = readNum<uint64_t>(source);
268270
for (uint64_t i = 0; i < expected; ++i) {
269-
auto info = ValidPathInfo::read(source, *this, 16);
271+
auto info = worker_proto::readValidPathInfo(*this,
272+
worker_proto::ReadConn {
273+
{ .from = source },
274+
.version = 16,
275+
});
270276
info.ultimate = false;
271277
addToStore(info, source, repair, checkSigs);
272278
}
@@ -978,6 +984,7 @@ std::map<StorePath, StorePath> copyPaths(
978984
return pathsMap;
979985
}
980986

987+
981988
std::map<StorePath, StorePath> copyPaths(
982989
Store & srcStore,
983990
Store & dstStore,
@@ -1013,7 +1020,12 @@ std::map<StorePath, StorePath> copyPaths(
10131020
PushActivity pact(act.id);
10141021

10151022
auto info = srcStore.queryPathInfo(storePath);
1016-
info->write(sink, srcStore, 16);
1023+
worker_proto::write(srcStore,
1024+
worker_proto::WriteConn {
1025+
{ .to = sink },
1026+
.version = 16,
1027+
},
1028+
*info);
10171029
srcStore.narFromPath(storePath, sink);
10181030
}
10191031
});

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)