mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
Use template structs instead of phantoms
This commit is contained in:
parent
3d8240c32e
commit
9ab07e99f5
8 changed files with 148 additions and 156 deletions
|
@ -1864,11 +1864,11 @@ HookReply DerivationGoal::tryBuildHook()
|
|||
|
||||
/* Tell the hook all the inputs that have to be copied to the
|
||||
remote system. */
|
||||
nix::worker_proto::write(worker.store, hook->sink, inputPaths);
|
||||
WorkerProto<StorePathSet>::write(worker.store, hook->sink, inputPaths);
|
||||
|
||||
/* Tell the hooks the missing outputs that have to be copied back
|
||||
from the remote system. */
|
||||
nix::worker_proto::write(worker.store, hook->sink, missingPaths);
|
||||
WorkerProto<StorePathSet>::write(worker.store, hook->sink, missingPaths);
|
||||
|
||||
hook->sink = FdSink();
|
||||
hook->toHook.writeSide = -1;
|
||||
|
|
|
@ -256,11 +256,11 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
}
|
||||
|
||||
case wopQueryValidPaths: {
|
||||
auto paths = nix::worker_proto::read(*store, from, Phantom<StorePathSet> {});
|
||||
auto paths = WorkerProto<StorePathSet>::read(*store, from);
|
||||
logger->startWork();
|
||||
auto res = store->queryValidPaths(paths);
|
||||
logger->stopWork();
|
||||
nix::worker_proto::write(*store, to, res);
|
||||
WorkerProto<StorePathSet>::write(*store, to, res);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -276,11 +276,11 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
}
|
||||
|
||||
case wopQuerySubstitutablePaths: {
|
||||
auto paths = nix::worker_proto::read(*store, from, Phantom<StorePathSet> {});
|
||||
auto paths = WorkerProto<StorePathSet>::read(*store, from);
|
||||
logger->startWork();
|
||||
auto res = store->querySubstitutablePaths(paths);
|
||||
logger->stopWork();
|
||||
nix::worker_proto::write(*store, to, res);
|
||||
WorkerProto<StorePathSet>::write(*store, to, res);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
paths = store->queryValidDerivers(path);
|
||||
else paths = store->queryDerivationOutputs(path);
|
||||
logger->stopWork();
|
||||
nix::worker_proto::write(*store, to, paths);
|
||||
WorkerProto<StorePathSet>::write(*store, to, paths);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -327,7 +327,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
logger->startWork();
|
||||
auto outputs = store->queryDerivationOutputMap(path);
|
||||
logger->stopWork();
|
||||
nix::worker_proto::write(*store, to, outputs);
|
||||
WorkerProto<std::map<std::string, std::optional<StorePath>>>::write(*store, to, outputs);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
case wopAddTextToStore: {
|
||||
string suffix = readString(from);
|
||||
string s = readString(from);
|
||||
auto refs = nix::worker_proto::read(*store, from, Phantom<StorePathSet> {});
|
||||
auto refs = WorkerProto<StorePathSet>::read(*store, from);
|
||||
logger->startWork();
|
||||
auto path = store->addTextToStore(suffix, s, refs, NoRepair);
|
||||
logger->stopWork();
|
||||
|
@ -518,7 +518,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
case wopCollectGarbage: {
|
||||
GCOptions options;
|
||||
options.action = (GCOptions::GCAction) readInt(from);
|
||||
options.pathsToDelete = nix::worker_proto::read(*store, from, Phantom<StorePathSet> {});
|
||||
options.pathsToDelete = WorkerProto<StorePathSet>::read(*store, from);
|
||||
from >> options.ignoreLiveness >> options.maxFreed;
|
||||
// obsolete fields
|
||||
readInt(from);
|
||||
|
@ -587,7 +587,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
else {
|
||||
to << 1
|
||||
<< (i->second.deriver ? store->printStorePath(*i->second.deriver) : "");
|
||||
nix::worker_proto::write(*store, to, i->second.references);
|
||||
WorkerProto<StorePathSet>::write(*store, to, i->second.references);
|
||||
to << i->second.downloadSize
|
||||
<< i->second.narSize;
|
||||
}
|
||||
|
@ -598,11 +598,11 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
SubstitutablePathInfos infos;
|
||||
StorePathCAMap pathsMap = {};
|
||||
if (GET_PROTOCOL_MINOR(clientVersion) < 22) {
|
||||
auto paths = nix::worker_proto::read(*store, from, Phantom<StorePathSet> {});
|
||||
auto paths = WorkerProto<StorePathSet>::read(*store, from);
|
||||
for (auto & path : paths)
|
||||
pathsMap.emplace(path, std::nullopt);
|
||||
} else
|
||||
pathsMap = nix::worker_proto::read(*store, from, Phantom<StorePathCAMap> {});
|
||||
pathsMap = WorkerProto<StorePathCAMap>::read(*store, from);
|
||||
logger->startWork();
|
||||
store->querySubstitutablePathInfos(pathsMap, infos);
|
||||
logger->stopWork();
|
||||
|
@ -610,7 +610,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
for (auto & i : infos) {
|
||||
to << store->printStorePath(i.first)
|
||||
<< (i.second.deriver ? store->printStorePath(*i.second.deriver) : "");
|
||||
nix::worker_proto::write(*store, to, i.second.references);
|
||||
WorkerProto<StorePathSet>::write(*store, to, i.second.references);
|
||||
to << i.second.downloadSize << i.second.narSize;
|
||||
}
|
||||
break;
|
||||
|
@ -620,7 +620,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
logger->startWork();
|
||||
auto paths = store->queryAllValidPaths();
|
||||
logger->stopWork();
|
||||
nix::worker_proto::write(*store, to, paths);
|
||||
WorkerProto<StorePathSet>::write(*store, to, paths);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -639,7 +639,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
to << 1;
|
||||
to << (info->deriver ? store->printStorePath(*info->deriver) : "")
|
||||
<< info->narHash->to_string(Base16, false);
|
||||
nix::worker_proto::write(*store, to, info->references);
|
||||
WorkerProto<StorePathSet>::write(*store, to, info->references);
|
||||
to << info->registrationTime << info->narSize;
|
||||
if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
|
||||
to << info->ultimate
|
||||
|
@ -699,7 +699,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
if (deriver != "")
|
||||
info.deriver = store->parseStorePath(deriver);
|
||||
info.narHash = Hash::parseAny(readString(from), htSHA256);
|
||||
info.references = nix::worker_proto::read(*store, from, Phantom<StorePathSet> {});
|
||||
info.references = WorkerProto<StorePathSet>::read(*store, from);
|
||||
from >> info.registrationTime >> info.narSize >> info.ultimate;
|
||||
info.sigs = readStrings<StringSet>(from);
|
||||
info.ca = parseContentAddressOpt(readString(from));
|
||||
|
@ -799,9 +799,9 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||
uint64_t downloadSize, narSize;
|
||||
store->queryMissing(targets, willBuild, willSubstitute, unknown, downloadSize, narSize);
|
||||
logger->stopWork();
|
||||
nix::worker_proto::write(*store, to, willBuild);
|
||||
nix::worker_proto::write(*store, to, willSubstitute);
|
||||
nix::worker_proto::write(*store, to, unknown);
|
||||
WorkerProto<StorePathSet>::write(*store, to, willBuild);
|
||||
WorkerProto<StorePathSet>::write(*store, to, willSubstitute);
|
||||
WorkerProto<StorePathSet>::write(*store, to, unknown);
|
||||
to << downloadSize << narSize;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -605,7 +605,7 @@ Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv,
|
|||
drv.outputs.emplace(std::move(name), std::move(output));
|
||||
}
|
||||
|
||||
drv.inputSrcs = nix::worker_proto::read(store, in, Phantom<StorePathSet> {});
|
||||
drv.inputSrcs = WorkerProto<StorePathSet>::read(store, in);
|
||||
in >> drv.platform >> drv.builder;
|
||||
drv.args = readStrings<Strings>(in);
|
||||
|
||||
|
@ -640,7 +640,7 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr
|
|||
},
|
||||
}, i.second.output);
|
||||
}
|
||||
nix::worker_proto::write(store, out, drv.inputSrcs);
|
||||
WorkerProto<StorePathSet>::write(store, out, drv.inputSrcs);
|
||||
out << drv.platform << drv.builder << drv.args;
|
||||
out << drv.env.size();
|
||||
for (auto & i : drv.env)
|
||||
|
|
|
@ -45,7 +45,7 @@ void Store::exportPath(const StorePath & path, Sink & sink)
|
|||
teeSink
|
||||
<< exportMagic
|
||||
<< printStorePath(path);
|
||||
nix::worker_proto::write(*this, teeSink, info->references);
|
||||
WorkerProto<StorePathSet>::write(*this, teeSink, info->references);
|
||||
teeSink
|
||||
<< (info->deriver ? printStorePath(*info->deriver) : "")
|
||||
<< 0;
|
||||
|
@ -73,7 +73,7 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
|
|||
|
||||
//Activity act(*logger, lvlInfo, format("importing path '%s'") % info.path);
|
||||
|
||||
info.references = nix::worker_proto::read(*this, source, Phantom<StorePathSet> {});
|
||||
info.references = WorkerProto<StorePathSet>::read(*this, source);
|
||||
|
||||
auto deriver = readString(source);
|
||||
if (deriver != "")
|
||||
|
|
|
@ -107,7 +107,7 @@ struct LegacySSHStore : public Store
|
|||
auto deriver = readString(conn->from);
|
||||
if (deriver != "")
|
||||
info->deriver = parseStorePath(deriver);
|
||||
info->references = nix::worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
info->references = WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
readLongLong(conn->from); // download size
|
||||
info->narSize = readLongLong(conn->from);
|
||||
|
||||
|
@ -139,7 +139,7 @@ struct LegacySSHStore : public Store
|
|||
<< printStorePath(info.path)
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< info.narHash->to_string(Base16, false);
|
||||
nix::worker_proto::write(*this, conn->to, info.references);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, info.references);
|
||||
conn->to
|
||||
<< info.registrationTime
|
||||
<< info.narSize
|
||||
|
@ -168,7 +168,7 @@ struct LegacySSHStore : public Store
|
|||
conn->to
|
||||
<< exportMagic
|
||||
<< printStorePath(info.path);
|
||||
nix::worker_proto::write(*this, conn->to, info.references);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, info.references);
|
||||
conn->to
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< 0
|
||||
|
@ -251,10 +251,10 @@ struct LegacySSHStore : public Store
|
|||
conn->to
|
||||
<< cmdQueryClosure
|
||||
<< includeOutputs;
|
||||
nix::worker_proto::write(*this, conn->to, paths);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, paths);
|
||||
conn->to.flush();
|
||||
|
||||
for (auto & i : nix::worker_proto::read(*this, conn->from, Phantom<StorePathSet> {}))
|
||||
for (auto & i : WorkerProto<StorePathSet>::read(*this, conn->from))
|
||||
out.insert(i);
|
||||
}
|
||||
|
||||
|
@ -267,10 +267,10 @@ struct LegacySSHStore : public Store
|
|||
<< cmdQueryValidPaths
|
||||
<< false // lock
|
||||
<< maybeSubstitute;
|
||||
nix::worker_proto::write(*this, conn->to, paths);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, paths);
|
||||
conn->to.flush();
|
||||
|
||||
return nix::worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
return WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
}
|
||||
|
||||
void connect() override
|
||||
|
|
|
@ -22,40 +22,36 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
namespace worker_proto {
|
||||
|
||||
std::string read(const Store & store, Source & from, Phantom<std::string> _)
|
||||
std::string WorkerProto<std::string>::read(const Store & store, Source & from)
|
||||
{
|
||||
return readString(from);
|
||||
}
|
||||
|
||||
void write(const Store & store, Sink & out, const std::string & str)
|
||||
void WorkerProto<std::string>::write(const Store & store, Sink & out, const std::string & str)
|
||||
{
|
||||
out << str;
|
||||
}
|
||||
|
||||
StorePath read(const Store & store, Source & from, Phantom<StorePath> _)
|
||||
StorePath WorkerProto<StorePath>::read(const Store & store, Source & from)
|
||||
{
|
||||
return store.parseStorePath(readString(from));
|
||||
}
|
||||
|
||||
void write(const Store & store, Sink & out, const StorePath & storePath)
|
||||
void WorkerProto<StorePath>::write(const Store & store, Sink & out, const StorePath & storePath)
|
||||
{
|
||||
out << store.printStorePath(storePath);
|
||||
}
|
||||
|
||||
ContentAddress read(const Store & store, Source & from, Phantom<ContentAddress> _)
|
||||
ContentAddress WorkerProto<ContentAddress>::read(const Store & store, Source & from)
|
||||
{
|
||||
return parseContentAddress(readString(from));
|
||||
}
|
||||
|
||||
void write(const Store & store, Sink & out, const ContentAddress & ca)
|
||||
void WorkerProto<ContentAddress>::write(const Store & store, Sink & out, const ContentAddress & ca)
|
||||
{
|
||||
out << renderContentAddress(ca);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* TODO: Separate these store impls into different files, give them better names */
|
||||
RemoteStore::RemoteStore(const Params & params)
|
||||
|
@ -290,9 +286,9 @@ StorePathSet RemoteStore::queryValidPaths(const StorePathSet & paths, Substitute
|
|||
return res;
|
||||
} else {
|
||||
conn->to << wopQueryValidPaths;
|
||||
nix::worker_proto::write(*this, conn->to, paths);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, paths);
|
||||
conn.processStderr();
|
||||
return worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
return WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,7 +298,7 @@ StorePathSet RemoteStore::queryAllValidPaths()
|
|||
auto conn(getConnection());
|
||||
conn->to << wopQueryAllValidPaths;
|
||||
conn.processStderr();
|
||||
return nix::worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
return WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
}
|
||||
|
||||
|
||||
|
@ -319,9 +315,9 @@ StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths)
|
|||
return res;
|
||||
} else {
|
||||
conn->to << wopQuerySubstitutablePaths;
|
||||
nix::worker_proto::write(*this, conn->to, paths);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, paths);
|
||||
conn.processStderr();
|
||||
return worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
return WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,7 +339,7 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
|
|||
auto deriver = readString(conn->from);
|
||||
if (deriver != "")
|
||||
info.deriver = parseStorePath(deriver);
|
||||
info.references = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
info.references = WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
info.downloadSize = readLongLong(conn->from);
|
||||
info.narSize = readLongLong(conn->from);
|
||||
infos.insert_or_assign(i.first, std::move(info));
|
||||
|
@ -356,9 +352,9 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
|
|||
StorePathSet paths;
|
||||
for (auto & path : pathsMap)
|
||||
paths.insert(path.first);
|
||||
worker_proto::write(*this, conn->to, paths);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, paths);
|
||||
} else
|
||||
worker_proto::write(*this, conn->to, pathsMap);
|
||||
WorkerProto<StorePathCAMap>::write(*this, conn->to, pathsMap);
|
||||
conn.processStderr();
|
||||
size_t count = readNum<size_t>(conn->from);
|
||||
for (size_t n = 0; n < count; n++) {
|
||||
|
@ -366,7 +362,7 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
|
|||
auto deriver = readString(conn->from);
|
||||
if (deriver != "")
|
||||
info.deriver = parseStorePath(deriver);
|
||||
info.references = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
info.references = WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
info.downloadSize = readLongLong(conn->from);
|
||||
info.narSize = readLongLong(conn->from);
|
||||
}
|
||||
|
@ -399,7 +395,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path,
|
|||
auto deriver = readString(conn->from);
|
||||
if (deriver != "") info->deriver = parseStorePath(deriver);
|
||||
info->narHash = Hash::parseAny(readString(conn->from), htSHA256);
|
||||
info->references = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
info->references = WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
conn->from >> info->registrationTime >> info->narSize;
|
||||
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) {
|
||||
conn->from >> info->ultimate;
|
||||
|
@ -418,7 +414,7 @@ void RemoteStore::queryReferrers(const StorePath & path,
|
|||
auto conn(getConnection());
|
||||
conn->to << wopQueryReferrers << printStorePath(path);
|
||||
conn.processStderr();
|
||||
for (auto & i : worker_proto::read(*this, conn->from, Phantom<StorePathSet> {}))
|
||||
for (auto & i : WorkerProto<StorePathSet>::read(*this, conn->from))
|
||||
referrers.insert(i);
|
||||
}
|
||||
|
||||
|
@ -428,7 +424,7 @@ StorePathSet RemoteStore::queryValidDerivers(const StorePath & path)
|
|||
auto conn(getConnection());
|
||||
conn->to << wopQueryValidDerivers << printStorePath(path);
|
||||
conn.processStderr();
|
||||
return worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
return WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
}
|
||||
|
||||
|
||||
|
@ -440,7 +436,7 @@ StorePathSet RemoteStore::queryDerivationOutputs(const StorePath & path)
|
|||
}
|
||||
conn->to << wopQueryDerivationOutputs << printStorePath(path);
|
||||
conn.processStderr();
|
||||
return worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
return WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
}
|
||||
|
||||
|
||||
|
@ -449,8 +445,7 @@ std::map<std::string, std::optional<StorePath>> RemoteStore::queryDerivationOutp
|
|||
auto conn(getConnection());
|
||||
conn->to << wopQueryDerivationOutputMap << printStorePath(path);
|
||||
conn.processStderr();
|
||||
return worker_proto::read(*this, conn->from, Phantom<std::map<std::string, std::optional<StorePath>>> {});
|
||||
|
||||
return WorkerProto<std::map<std::string, std::optional<StorePath>>>::read(*this, conn->from);
|
||||
}
|
||||
|
||||
std::optional<StorePath> RemoteStore::queryPathFromHashPart(const std::string & hashPart)
|
||||
|
@ -479,7 +474,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
|||
sink
|
||||
<< exportMagic
|
||||
<< printStorePath(info.path);
|
||||
worker_proto::write(*this, sink, info.references);
|
||||
WorkerProto<StorePathSet>::write(*this, sink, info.references);
|
||||
sink
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< 0 // == no legacy signature
|
||||
|
@ -489,7 +484,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
|||
|
||||
conn.processStderr(0, source2.get());
|
||||
|
||||
auto importedPaths = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
auto importedPaths = WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
assert(importedPaths.size() <= 1);
|
||||
}
|
||||
|
||||
|
@ -498,7 +493,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
|||
<< printStorePath(info.path)
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< info.narHash->to_string(Base16, false);
|
||||
worker_proto::write(*this, conn->to, info.references);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, info.references);
|
||||
conn->to << info.registrationTime << info.narSize
|
||||
<< info.ultimate << info.sigs << renderContentAddress(info.ca)
|
||||
<< repair << !checkSigs;
|
||||
|
@ -631,7 +626,7 @@ StorePath RemoteStore::addTextToStore(const string & name, const string & s,
|
|||
|
||||
auto conn(getConnection());
|
||||
conn->to << wopAddTextToStore << name << s;
|
||||
worker_proto::write(*this, conn->to, references);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, references);
|
||||
|
||||
conn.processStderr();
|
||||
return parseStorePath(readString(conn->from));
|
||||
|
@ -733,7 +728,7 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
|||
|
||||
conn->to
|
||||
<< wopCollectGarbage << options.action;
|
||||
worker_proto::write(*this, conn->to, options.pathsToDelete);
|
||||
WorkerProto<StorePathSet>::write(*this, conn->to, options.pathsToDelete);
|
||||
conn->to << options.ignoreLiveness
|
||||
<< options.maxFreed
|
||||
/* removed options */
|
||||
|
@ -795,9 +790,9 @@ void RemoteStore::queryMissing(const std::vector<StorePathWithOutputs> & targets
|
|||
ss.push_back(p.to_string(*this));
|
||||
conn->to << ss;
|
||||
conn.processStderr();
|
||||
willBuild = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
willSubstitute = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
unknown = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
|
||||
willBuild = WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
willSubstitute = WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
unknown = WorkerProto<StorePathSet>::read(*this, conn->from);
|
||||
conn->from >> downloadSize >> narSize;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -66,105 +66,102 @@ typedef enum {
|
|||
class Store;
|
||||
struct Source;
|
||||
|
||||
/* To guide overloading */
|
||||
template<typename T>
|
||||
struct Phantom {};
|
||||
struct WorkerProto {
|
||||
static T read(const Store & store, Source & from);
|
||||
static void write(const Store & store, Sink & out, const T & t);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct WorkerProto<std::string> {
|
||||
static std::string read(const Store & store, Source & from);
|
||||
static void write(const Store & store, Sink & out, const std::string & t);
|
||||
};
|
||||
|
||||
namespace worker_proto {
|
||||
/* FIXME maybe move more stuff inside here */
|
||||
template<>
|
||||
struct WorkerProto<StorePath> {
|
||||
static StorePath read(const Store & store, Source & from);
|
||||
static void write(const Store & store, Sink & out, const StorePath & t);
|
||||
};
|
||||
|
||||
std::string read(const Store & store, Source & from, Phantom<std::string> _);
|
||||
void write(const Store & store, Sink & out, const std::string & str);
|
||||
|
||||
StorePath read(const Store & store, Source & from, Phantom<StorePath> _);
|
||||
void write(const Store & store, Sink & out, const StorePath & storePath);
|
||||
|
||||
ContentAddress read(const Store & store, Source & from, Phantom<ContentAddress> _);
|
||||
void write(const Store & store, Sink & out, const ContentAddress & ca);
|
||||
template<>
|
||||
struct WorkerProto<ContentAddress> {
|
||||
static ContentAddress read(const Store & store, Source & from);
|
||||
static void write(const Store & store, Sink & out, const ContentAddress & t);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::set<T> read(const Store & store, Source & from, Phantom<std::set<T>> _);
|
||||
template<typename T>
|
||||
void write(const Store & store, Sink & out, const std::set<T> & resSet);
|
||||
struct WorkerProto<std::set<T>> {
|
||||
|
||||
template<typename K, typename V>
|
||||
std::map<K, V> read(const Store & store, Source & from, Phantom<std::map<K, V>> _);
|
||||
template<typename K, typename V>
|
||||
void write(const Store & store, Sink & out, const std::map<K, V> & resMap);
|
||||
|
||||
template<typename T>
|
||||
std::optional<T> read(const Store & store, Source & from, Phantom<std::optional<T>> _);
|
||||
template<typename T>
|
||||
void write(const Store & store, Sink & out, const std::optional<T> & optVal);
|
||||
|
||||
template<typename T>
|
||||
std::set<T> read(const Store & store, Source & from, Phantom<std::set<T>> _)
|
||||
static std::set<T> read(const Store & store, Source & from)
|
||||
{
|
||||
std::set<T> resSet;
|
||||
auto size = readNum<size_t>(from);
|
||||
while (size--) {
|
||||
resSet.insert(read(store, from, Phantom<T> {}));
|
||||
resSet.insert(WorkerProto<T>::read(store, from));
|
||||
}
|
||||
return resSet;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void write(const Store & store, Sink & out, const std::set<T> & resSet)
|
||||
static void write(const Store & store, Sink & out, const std::set<T> & resSet)
|
||||
{
|
||||
out << resSet.size();
|
||||
for (auto & key : resSet) {
|
||||
write(store, out, key);
|
||||
WorkerProto<T>::write(store, out, key);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename K, typename V>
|
||||
std::map<K, V> read(const Store & store, Source & from, Phantom<std::map<K, V>> _)
|
||||
struct WorkerProto<std::map<K, V>> {
|
||||
|
||||
static std::map<K, V> read(const Store & store, Source & from)
|
||||
{
|
||||
std::map<K, V> resMap;
|
||||
auto size = readNum<size_t>(from);
|
||||
while (size--) {
|
||||
resMap.insert_or_assign(
|
||||
read(store, from, Phantom<K> {}),
|
||||
read(store, from, Phantom<V> {}));
|
||||
WorkerProto<K>::read(store, from),
|
||||
WorkerProto<V>::read(store, from));
|
||||
}
|
||||
return resMap;
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
void write(const Store & store, Sink & out, const std::map<K, V> & resMap)
|
||||
static void write(const Store & store, Sink & out, const std::map<K, V> & resMap)
|
||||
{
|
||||
out << resMap.size();
|
||||
for (auto & i : resMap) {
|
||||
write(store, out, i.first);
|
||||
write(store, out, i.second);
|
||||
WorkerProto<K>::write(store, out, i.first);
|
||||
WorkerProto<V>::write(store, out, i.second);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::optional<T> read(const Store & store, Source & from, Phantom<std::optional<T>> _)
|
||||
struct WorkerProto<std::optional<T>> {
|
||||
|
||||
static std::optional<T> read(const Store & store, Source & from)
|
||||
{
|
||||
auto tag = readNum<uint8_t>(from);
|
||||
switch (tag) {
|
||||
case 0:
|
||||
return std::nullopt;
|
||||
case 1:
|
||||
return read(store, from, Phantom<T> {});
|
||||
return WorkerProto<T>::read(store, from);
|
||||
default:
|
||||
throw Error("got an invalid tag bit for std::optional: %#04x", (size_t)tag);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void write(const Store & store, Sink & out, const std::optional<T> & optVal)
|
||||
static void write(const Store & store, Sink & out, const std::optional<T> & optVal)
|
||||
{
|
||||
out << (uint64_t) (optVal ? 1 : 0);
|
||||
if (optVal)
|
||||
nix::worker_proto::write(store, out, *optVal);
|
||||
}
|
||||
|
||||
|
||||
WorkerProto<T>::write(store, out, *optVal);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -815,7 +815,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
case cmdQueryValidPaths: {
|
||||
bool lock = readInt(in);
|
||||
bool substitute = readInt(in);
|
||||
auto paths = nix::worker_proto::read(*store, in, Phantom<StorePathSet> {});
|
||||
auto paths = WorkerProto<StorePathSet>::read(*store, in);
|
||||
if (lock && writeAllowed)
|
||||
for (auto & path : paths)
|
||||
store->addTempRoot(path);
|
||||
|
@ -845,19 +845,19 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
}
|
||||
}
|
||||
|
||||
nix::worker_proto::write(*store, out, store->queryValidPaths(paths));
|
||||
WorkerProto<StorePathSet>::write(*store, out, store->queryValidPaths(paths));
|
||||
break;
|
||||
}
|
||||
|
||||
case cmdQueryPathInfos: {
|
||||
auto paths = nix::worker_proto::read(*store, in, Phantom<StorePathSet> {});
|
||||
auto paths = WorkerProto<StorePathSet>::read(*store, in);
|
||||
// !!! Maybe we want a queryPathInfos?
|
||||
for (auto & i : paths) {
|
||||
try {
|
||||
auto info = store->queryPathInfo(i);
|
||||
out << store->printStorePath(info->path)
|
||||
<< (info->deriver ? store->printStorePath(*info->deriver) : "");
|
||||
nix::worker_proto::write(*store, out, info->references);
|
||||
WorkerProto<StorePathSet>::write(*store, out, info->references);
|
||||
// !!! Maybe we want compression?
|
||||
out << info->narSize // downloadSize
|
||||
<< info->narSize;
|
||||
|
@ -885,7 +885,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
|
||||
case cmdExportPaths: {
|
||||
readInt(in); // obsolete
|
||||
store->exportPaths(nix::worker_proto::read(*store, in, Phantom<StorePathSet> {}), out);
|
||||
store->exportPaths(WorkerProto<StorePathSet>::read(*store, in), out);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -934,9 +934,9 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
case cmdQueryClosure: {
|
||||
bool includeOutputs = readInt(in);
|
||||
StorePathSet closure;
|
||||
store->computeFSClosure(nix::worker_proto::read(*store, in, Phantom<StorePathSet> {}),
|
||||
store->computeFSClosure(WorkerProto<StorePathSet>::read(*store, in),
|
||||
closure, false, includeOutputs);
|
||||
nix::worker_proto::write(*store, out, closure);
|
||||
WorkerProto<StorePathSet>::write(*store, out, closure);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -949,7 +949,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
if (deriver != "")
|
||||
info.deriver = store->parseStorePath(deriver);
|
||||
info.narHash = Hash::parseAny(readString(in), htSHA256);
|
||||
info.references = nix::worker_proto::read(*store, in, Phantom<StorePathSet> {});
|
||||
info.references = WorkerProto<StorePathSet>::read(*store, in);
|
||||
in >> info.registrationTime >> info.narSize >> info.ultimate;
|
||||
info.sigs = readStrings<StringSet>(in);
|
||||
info.ca = parseContentAddressOpt(readString(in));
|
||||
|
|
Loading…
Reference in a new issue