mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
Daemon protocol: Use the WorkerProto serializer for store paths
This commit is contained in:
parent
0503a862ef
commit
d782c5e586
2 changed files with 53 additions and 48 deletions
|
|
@ -312,7 +312,7 @@ static void performOp(
|
|||
switch (op) {
|
||||
|
||||
case WorkerProto::Op::IsValidPath: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
bool result = store->isValidPath(path);
|
||||
logger->stopWork();
|
||||
|
|
@ -339,7 +339,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::HasSubstitutes: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
StorePathSet paths; // FIXME
|
||||
paths.insert(path);
|
||||
|
|
@ -359,7 +359,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::QueryPathHash: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
auto hash = store->queryPathInfo(path)->narHash;
|
||||
logger->stopWork();
|
||||
|
|
@ -371,7 +371,7 @@ static void performOp(
|
|||
case WorkerProto::Op::QueryReferrers:
|
||||
case WorkerProto::Op::QueryValidDerivers:
|
||||
case WorkerProto::Op::QueryDerivationOutputs: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
StorePathSet paths;
|
||||
if (op == WorkerProto::Op::QueryReferences)
|
||||
|
|
@ -389,7 +389,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::QueryDerivationOutputNames: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
auto names = store->readDerivation(path).outputNames();
|
||||
logger->stopWork();
|
||||
|
|
@ -398,7 +398,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::QueryDerivationOutputMap: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
auto outputs = store->queryPartialDerivationOutputMap(path);
|
||||
logger->stopWork();
|
||||
|
|
@ -407,11 +407,11 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::QueryDeriver: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
auto info = store->queryPathInfo(path);
|
||||
logger->stopWork();
|
||||
conn.to << (info->deriver ? store->printStorePath(*info->deriver) : "");
|
||||
WorkerProto::write(*store, conn, info->deriver);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -420,7 +420,7 @@ static void performOp(
|
|||
logger->startWork();
|
||||
auto path = store->queryPathFromHashPart(hashPart);
|
||||
logger->stopWork();
|
||||
conn.to << (path ? store->printStorePath(*path) : "");
|
||||
WorkerProto::write(*store, conn, path);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -505,7 +505,7 @@ static void performOp(
|
|||
store->addToStoreFromDump(*dumpSource, baseName, FileSerialisationMethod::NixArchive, method, hashAlgo);
|
||||
logger->stopWork();
|
||||
|
||||
conn.to << store->printStorePath(path);
|
||||
WorkerProto::write(*store, wconn, path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -542,7 +542,7 @@ static void performOp(
|
|||
NoRepair);
|
||||
});
|
||||
logger->stopWork();
|
||||
conn.to << store->printStorePath(path);
|
||||
WorkerProto::write(*store, wconn, path);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -591,7 +591,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::BuildDerivation: {
|
||||
auto drvPath = store->parseStorePath(readString(conn.from));
|
||||
auto drvPath = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
BasicDerivation drv;
|
||||
/*
|
||||
* Note: unlike wopEnsurePath, this operation reads a
|
||||
|
|
@ -668,7 +668,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::EnsurePath: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
store->ensurePath(path);
|
||||
logger->stopWork();
|
||||
|
|
@ -677,7 +677,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::AddTempRoot: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
store->addTempRoot(path);
|
||||
logger->stopWork();
|
||||
|
|
@ -733,8 +733,10 @@ static void performOp(
|
|||
conn.to << size;
|
||||
|
||||
for (auto & [target, links] : roots)
|
||||
for (auto & link : links)
|
||||
conn.to << link << store->printStorePath(target);
|
||||
for (auto & link : links) {
|
||||
conn.to << link;
|
||||
WorkerProto::write(*store, wconn, target);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -799,7 +801,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::QuerySubstitutablePathInfo: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
SubstitutablePathInfos infos;
|
||||
store->querySubstitutablePathInfos({{path, std::nullopt}}, infos);
|
||||
|
|
@ -808,7 +810,8 @@ static void performOp(
|
|||
if (i == infos.end())
|
||||
conn.to << 0;
|
||||
else {
|
||||
conn.to << 1 << (i->second.deriver ? store->printStorePath(*i->second.deriver) : "");
|
||||
conn.to << 1;
|
||||
WorkerProto::write(*store, wconn, i->second.deriver);
|
||||
WorkerProto::write(*store, wconn, i->second.references);
|
||||
conn.to << i->second.downloadSize << i->second.narSize;
|
||||
}
|
||||
|
|
@ -829,8 +832,8 @@ static void performOp(
|
|||
logger->stopWork();
|
||||
conn.to << infos.size();
|
||||
for (auto & i : infos) {
|
||||
conn.to << store->printStorePath(i.first)
|
||||
<< (i.second.deriver ? store->printStorePath(*i.second.deriver) : "");
|
||||
WorkerProto::write(*store, wconn, i.first);
|
||||
WorkerProto::write(*store, wconn, i.second.deriver);
|
||||
WorkerProto::write(*store, wconn, i.second.references);
|
||||
conn.to << i.second.downloadSize << i.second.narSize;
|
||||
}
|
||||
|
|
@ -846,7 +849,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::QueryPathInfo: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
std::shared_ptr<const ValidPathInfo> info;
|
||||
logger->startWork();
|
||||
info = store->queryPathInfo(path);
|
||||
|
|
@ -880,7 +883,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::AddSignatures: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
StringSet sigs = readStrings<StringSet>(conn.from);
|
||||
logger->startWork();
|
||||
store->addSignatures(path, sigs);
|
||||
|
|
@ -890,7 +893,7 @@ static void performOp(
|
|||
}
|
||||
|
||||
case WorkerProto::Op::NarFromPath: {
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
logger->stopWork();
|
||||
dumpPath(store->toRealPath(path), conn.to);
|
||||
|
|
@ -899,12 +902,11 @@ static void performOp(
|
|||
|
||||
case WorkerProto::Op::AddToStoreNar: {
|
||||
bool repair, dontCheckSigs;
|
||||
auto path = store->parseStorePath(readString(conn.from));
|
||||
auto deriver = readString(conn.from);
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
|
||||
auto deriver = WorkerProto::Serialise<std::optional<StorePath>>::read(*store, rconn);
|
||||
auto narHash = Hash::parseAny(readString(conn.from), HashAlgorithm::SHA256);
|
||||
ValidPathInfo info{path, narHash};
|
||||
if (deriver != "")
|
||||
info.deriver = store->parseStorePath(deriver);
|
||||
info.deriver = std::move(deriver);
|
||||
info.references = WorkerProto::Serialise<StorePathSet>::read(*store, rconn);
|
||||
conn.from >> info.registrationTime >> info.narSize >> info.ultimate;
|
||||
info.sigs = readStrings<StringSet>(conn.from);
|
||||
|
|
|
|||
|
|
@ -159,7 +159,8 @@ void RemoteStore::setOptions()
|
|||
bool RemoteStore::isValidPathUncached(const StorePath & path)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::IsValidPath << printStorePath(path);
|
||||
conn->to << WorkerProto::Op::IsValidPath;
|
||||
WorkerProto::write(*this, *conn, path);
|
||||
conn.processStderr();
|
||||
return readInt(conn->from);
|
||||
}
|
||||
|
|
@ -205,10 +206,8 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
|
|||
conn.processStderr();
|
||||
size_t count = readNum<size_t>(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);
|
||||
SubstitutablePathInfo & info(infos[WorkerProto::Serialise<StorePath>::read(*this, *conn)]);
|
||||
info.deriver = WorkerProto::Serialise<std::optional<StorePath>>::read(*this, *conn);
|
||||
info.references = WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
|
||||
info.downloadSize = readLongLong(conn->from);
|
||||
info.narSize = readLongLong(conn->from);
|
||||
|
|
@ -235,7 +234,8 @@ void RemoteStore::queryPathInfoUncached(
|
|||
void RemoteStore::queryReferrers(const StorePath & path, StorePathSet & referrers)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::QueryReferrers << printStorePath(path);
|
||||
conn->to << WorkerProto::Op::QueryReferrers;
|
||||
WorkerProto::write(*this, *conn, path);
|
||||
conn.processStderr();
|
||||
for (auto & i : WorkerProto::Serialise<StorePathSet>::read(*this, *conn))
|
||||
referrers.insert(i);
|
||||
|
|
@ -244,7 +244,8 @@ void RemoteStore::queryReferrers(const StorePath & path, StorePathSet & referrer
|
|||
StorePathSet RemoteStore::queryValidDerivers(const StorePath & path)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::QueryValidDerivers << printStorePath(path);
|
||||
conn->to << WorkerProto::Op::QueryValidDerivers;
|
||||
WorkerProto::write(*this, *conn, path);
|
||||
conn.processStderr();
|
||||
return WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
|
||||
}
|
||||
|
|
@ -255,7 +256,8 @@ StorePathSet RemoteStore::queryDerivationOutputs(const StorePath & path)
|
|||
return Store::queryDerivationOutputs(path);
|
||||
}
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::QueryDerivationOutputs << printStorePath(path);
|
||||
conn->to << WorkerProto::Op::QueryDerivationOutputs;
|
||||
WorkerProto::write(*this, *conn, path);
|
||||
conn.processStderr();
|
||||
return WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
|
||||
}
|
||||
|
|
@ -266,7 +268,8 @@ RemoteStore::queryPartialDerivationOutputMap(const StorePath & path, Store * eva
|
|||
if (GET_PROTOCOL_MINOR(getProtocol()) >= 0x16) {
|
||||
if (!evalStore_) {
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::QueryDerivationOutputMap << printStorePath(path);
|
||||
conn->to << WorkerProto::Op::QueryDerivationOutputMap;
|
||||
WorkerProto::write(*this, *conn, path);
|
||||
conn.processStderr();
|
||||
return WorkerProto::Serialise<std::map<std::string, std::optional<StorePath>>>::read(*this, *conn);
|
||||
} else {
|
||||
|
|
@ -299,10 +302,7 @@ std::optional<StorePath> RemoteStore::queryPathFromHashPart(const std::string &
|
|||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::QueryPathFromHashPart << hashPart;
|
||||
conn.processStderr();
|
||||
Path path = readString(conn->from);
|
||||
if (path.empty())
|
||||
return {};
|
||||
return parseStorePath(path);
|
||||
return WorkerProto::Serialise<std::optional<StorePath>>::read(*this, *conn);
|
||||
}
|
||||
|
||||
ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
||||
|
|
@ -384,7 +384,7 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
|||
break;
|
||||
}
|
||||
}
|
||||
auto path = parseStorePath(readString(conn->from));
|
||||
auto path = WorkerProto::Serialise<StorePath>::read(*this, *conn);
|
||||
// Release our connection to prevent a deadlock in queryPathInfo().
|
||||
conn_.reset();
|
||||
return queryPathInfo(path);
|
||||
|
|
@ -426,9 +426,10 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, Repair
|
|||
{
|
||||
auto conn(getConnection());
|
||||
|
||||
conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path)
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< info.narHash.to_string(HashFormat::Base16, false);
|
||||
conn->to << WorkerProto::Op::AddToStoreNar;
|
||||
WorkerProto::write(*this, *conn, info.path);
|
||||
WorkerProto::write(*this, *conn, info.deriver);
|
||||
conn->to << info.narHash.to_string(HashFormat::Base16, false);
|
||||
WorkerProto::write(*this, *conn, info.references);
|
||||
conn->to << info.registrationTime << info.narSize << info.ultimate << info.sigs << renderContentAddress(info.ca)
|
||||
<< repair << !checkSigs;
|
||||
|
|
@ -663,7 +664,8 @@ BuildResult RemoteStore::buildDerivation(const StorePath & drvPath, const BasicD
|
|||
void RemoteStore::ensurePath(const StorePath & path)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::EnsurePath << printStorePath(path);
|
||||
conn->to << WorkerProto::Op::EnsurePath;
|
||||
WorkerProto::write(*this, *conn, path);
|
||||
conn.processStderr();
|
||||
readInt(conn->from);
|
||||
}
|
||||
|
|
@ -683,8 +685,7 @@ Roots RemoteStore::findRoots(bool censor)
|
|||
Roots result;
|
||||
while (count--) {
|
||||
Path link = readString(conn->from);
|
||||
auto target = parseStorePath(readString(conn->from));
|
||||
result[std::move(target)].emplace(link);
|
||||
result[WorkerProto::Serialise<StorePath>::read(*this, *conn)].emplace(link);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -728,7 +729,9 @@ bool RemoteStore::verifyStore(bool checkContents, RepairFlag repair)
|
|||
void RemoteStore::addSignatures(const StorePath & storePath, const StringSet & sigs)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::AddSignatures << printStorePath(storePath) << sigs;
|
||||
conn->to << WorkerProto::Op::AddSignatures;
|
||||
WorkerProto::write(*this, *conn, storePath);
|
||||
conn->to << sigs;
|
||||
conn.processStderr();
|
||||
readInt(conn->from);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue