Deduplicate protocol code more with ServeProto::BasicClientConnection

I did this in Nix for this purpose, but didn't get around to actually
taking advantage of it here, until now.
This commit is contained in:
John Ericson
2025-10-15 17:58:14 -04:00
parent f1463d4bce
commit 58846b0a1c

View File

@@ -103,9 +103,9 @@ static void copyClosureTo(
std::unique_lock<std::timed_mutex> sendLock(conn.machine->state->sendLock, std::unique_lock<std::timed_mutex> sendLock(conn.machine->state->sendLock,
std::chrono::seconds(600)); std::chrono::seconds(600));
conn.to << ServeProto::Command::ImportPaths; conn.importPaths(destStore, [&](Sink & sink) {
destStore.exportPaths(missing, conn.to); destStore.exportPaths(missing, sink);
conn.to.flush(); });
if (readInt(conn.from) != 1) if (readInt(conn.from) != 1)
throw Error("remote machine failed to import closure"); throw Error("remote machine failed to import closure");
@@ -298,12 +298,11 @@ static void copyPathFromRemote(
lambda function only gets executed if someone tries to read lambda function only gets executed if someone tries to read
from source2, we will send the command from here rather from source2, we will send the command from here rather
than outside the lambda. */ than outside the lambda. */
conn.to << ServeProto::Command::DumpStorePath << localStore.printStorePath(info.path); conn.narFromPath(localStore, info.path, [&](Source & source) {
conn.to.flush(); TeeSource tee(source, sink);
TeeSource tee(conn.from, sink);
extractNarData(tee, localStore.printStorePath(info.path), narMembers); extractNarData(tee, localStore.printStorePath(info.path), narMembers);
}); });
});
destStore.addToStore(info, *source2, NoRepair, NoCheckSigs); destStore.addToStore(info, *source2, NoRepair, NoCheckSigs);
} }