Merge pull request #1322 from NixOS/use-UnkeyedValidPathInfo-serializer

Use `ServeProto::Serialise<UnkeyedValidPathInfo>` for `QueryValidPaths`
This commit is contained in:
John Ericson 2023-12-10 11:52:56 -05:00 committed by GitHub
commit 105fd18fee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 25 deletions

6
flake.lock generated
View File

@ -59,11 +59,11 @@
"nixpkgs-regression": "nixpkgs-regression" "nixpkgs-regression": "nixpkgs-regression"
}, },
"locked": { "locked": {
"lastModified": 1701948782, "lastModified": 1702090558,
"narHash": "sha256-rEu4hLHZIy3fgf88BpiaVfl79hNSESRfQNbmxAO5uzg=", "narHash": "sha256-JzuGOltp5Ht9flroZ7g0erD5ud2okNQChw9YlxWDX3c=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nix", "repo": "nix",
"rev": "c3827ff6348a4d5199eaddf8dbc2ca2e2ef46ec5", "rev": "c8458bd731eb1c74159bebe459ea00165e056b65",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -154,7 +154,7 @@ static void copyClosureTo(
// FIXME: use Store::topoSortPaths(). // FIXME: use Store::topoSortPaths().
static StorePaths reverseTopoSortPaths(const std::map<StorePath, ValidPathInfo> & paths) static StorePaths reverseTopoSortPaths(const std::map<StorePath, UnkeyedValidPathInfo> & paths)
{ {
StorePaths sorted; StorePaths sorted;
StorePathSet visited; StorePathSet visited;
@ -322,7 +322,7 @@ static BuildResult performBuild(
return result; return result;
} }
static std::map<StorePath, ValidPathInfo> queryPathInfos( static std::map<StorePath, UnkeyedValidPathInfo> queryPathInfos(
Machine::Connection & conn, Machine::Connection & conn,
Store & localStore, Store & localStore,
StorePathSet & outputs, StorePathSet & outputs,
@ -331,30 +331,17 @@ static std::map<StorePath, ValidPathInfo> queryPathInfos(
{ {
/* Get info about each output path. */ /* Get info about each output path. */
std::map<StorePath, ValidPathInfo> infos; std::map<StorePath, UnkeyedValidPathInfo> infos;
conn.to << ServeProto::Command::QueryPathInfos; conn.to << ServeProto::Command::QueryPathInfos;
ServeProto::write(localStore, conn, outputs); ServeProto::write(localStore, conn, outputs);
conn.to.flush(); conn.to.flush();
while (true) { while (true) {
auto storePathS = readString(conn.from); auto storePathS = readString(conn.from);
if (storePathS == "") break; if (storePathS == "") break;
auto deriver = readString(conn.from); // deriver
auto references = ServeProto::Serialise<StorePathSet>::read(localStore, conn); auto storePath = localStore.parseStorePath(storePathS);
readLongLong(conn.from); // download size auto info = ServeProto::Serialise<UnkeyedValidPathInfo>::read(localStore, conn);
auto narSize = readLongLong(conn.from); infos.insert_or_assign(std::move(storePath), std::move(info));
auto narHash = Hash::parseAny(readString(conn.from), HashAlgorithm::SHA256);
auto ca = ContentAddress::parseOpt(readString(conn.from));
readStrings<StringSet>(conn.from); // sigs
ValidPathInfo info(localStore.parseStorePath(storePathS), narHash);
assert(outputs.count(info.path));
info.references = references;
info.narSize = narSize;
totalNarSize += info.narSize;
info.narHash = narHash;
info.ca = ca;
if (deriver != "")
info.deriver = localStore.parseStorePath(deriver);
infos.insert_or_assign(info.path, info);
} }
return infos; return infos;
@ -395,14 +382,16 @@ static void copyPathsFromRemote(
NarMemberDatas & narMembers, NarMemberDatas & narMembers,
Store & localStore, Store & localStore,
Store & destStore, Store & destStore,
const std::map<StorePath, ValidPathInfo> & infos const std::map<StorePath, UnkeyedValidPathInfo> & infos
) )
{ {
auto pathsSorted = reverseTopoSortPaths(infos); auto pathsSorted = reverseTopoSortPaths(infos);
for (auto & path : pathsSorted) { for (auto & path : pathsSorted) {
auto & info = infos.find(path)->second; auto & info = infos.find(path)->second;
copyPathFromRemote(conn, narMembers, localStore, destStore, info); copyPathFromRemote(
conn, narMembers, localStore, destStore,
ValidPathInfo { path, info });
} }
} }