1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-14 13:01:05 +01:00

Daemon protocol: Use the WorkerProto serializer for store paths

This commit is contained in:
Eelco Dolstra 2025-10-16 16:57:43 +02:00
parent 0503a862ef
commit d782c5e586
2 changed files with 53 additions and 48 deletions

View file

@ -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);
}