More cleanup
This commit is contained in:
parent
6bd2c7bb38
commit
b3491c781c
9 changed files with 184 additions and 296 deletions
|
|
@ -1528,22 +1528,14 @@ void LocalStore::exportPath(const Path & path, bool sign,
|
|||
throw Error(format("hash of path ‘%1%’ has changed from ‘%2%’ to ‘%3%’!") % path
|
||||
% printHash(storedHash) % printHash(hash));
|
||||
|
||||
writeInt(EXPORT_MAGIC, hashAndWriteSink);
|
||||
|
||||
writeString(path, hashAndWriteSink);
|
||||
|
||||
PathSet references;
|
||||
queryReferences(path, references);
|
||||
writeStrings(references, hashAndWriteSink);
|
||||
|
||||
Path deriver = queryDeriver(path);
|
||||
writeString(deriver, hashAndWriteSink);
|
||||
hashAndWriteSink << EXPORT_MAGIC << path << references << queryDeriver(path);
|
||||
|
||||
if (sign) {
|
||||
Hash hash = hashAndWriteSink.currentHash();
|
||||
|
||||
writeInt(1, hashAndWriteSink);
|
||||
|
||||
Path tmpDir = createTempDir();
|
||||
AutoDelete delTmp(tmpDir);
|
||||
Path hashFile = tmpDir + "/hash";
|
||||
|
|
@ -1561,10 +1553,10 @@ void LocalStore::exportPath(const Path & path, bool sign,
|
|||
args.push_back(hashFile);
|
||||
string signature = runProgram(OPENSSL_PATH, true, args);
|
||||
|
||||
writeString(signature, hashAndWriteSink);
|
||||
hashAndWriteSink << 1 << signature;
|
||||
|
||||
} else
|
||||
writeInt(0, hashAndWriteSink);
|
||||
hashAndWriteSink << 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ void RemoteStore::openConnection(bool reserveSpace)
|
|||
|
||||
/* Send the magic greeting, check for the reply. */
|
||||
try {
|
||||
writeInt(WORKER_MAGIC_1, to);
|
||||
to << WORKER_MAGIC_1;
|
||||
to.flush();
|
||||
unsigned int magic = readInt(from);
|
||||
if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
|
||||
|
|
@ -71,19 +71,18 @@ void RemoteStore::openConnection(bool reserveSpace)
|
|||
daemonVersion = readInt(from);
|
||||
if (GET_PROTOCOL_MAJOR(daemonVersion) != GET_PROTOCOL_MAJOR(PROTOCOL_VERSION))
|
||||
throw Error("Nix daemon protocol version not supported");
|
||||
writeInt(PROTOCOL_VERSION, to);
|
||||
to << PROTOCOL_VERSION;
|
||||
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 14) {
|
||||
int cpu = settings.lockCPU ? lockToCurrentCPU() : -1;
|
||||
if (cpu != -1) {
|
||||
writeInt(1, to);
|
||||
writeInt(cpu, to);
|
||||
} else
|
||||
writeInt(0, to);
|
||||
if (cpu != -1)
|
||||
to << 1 << cpu;
|
||||
else
|
||||
to << 0;
|
||||
}
|
||||
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 11)
|
||||
writeInt(reserveSpace, to);
|
||||
to << reserveSpace;
|
||||
|
||||
processStderr();
|
||||
}
|
||||
|
|
@ -141,35 +140,31 @@ RemoteStore::~RemoteStore()
|
|||
|
||||
void RemoteStore::setOptions()
|
||||
{
|
||||
writeInt(wopSetOptions, to);
|
||||
|
||||
writeInt(settings.keepFailed, to);
|
||||
writeInt(settings.keepGoing, to);
|
||||
writeInt(settings.tryFallback, to);
|
||||
writeInt(verbosity, to);
|
||||
writeInt(settings.maxBuildJobs, to);
|
||||
writeInt(settings.maxSilentTime, to);
|
||||
to << wopSetOptions
|
||||
<< settings.keepFailed
|
||||
<< settings.keepGoing
|
||||
<< settings.tryFallback
|
||||
<< verbosity
|
||||
<< settings.maxBuildJobs
|
||||
<< settings.maxSilentTime;
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 2)
|
||||
writeInt(settings.useBuildHook, to);
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 4) {
|
||||
writeInt(settings.buildVerbosity, to);
|
||||
writeInt(logType, to);
|
||||
writeInt(settings.printBuildTrace, to);
|
||||
}
|
||||
to << settings.useBuildHook;
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 4)
|
||||
to << settings.buildVerbosity
|
||||
<< logType
|
||||
<< settings.printBuildTrace;
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 6)
|
||||
writeInt(settings.buildCores, to);
|
||||
to << settings.buildCores;
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 10)
|
||||
writeInt(settings.useSubstitutes, to);
|
||||
to << settings.useSubstitutes;
|
||||
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 12) {
|
||||
Settings::SettingsMap overrides = settings.getOverrides();
|
||||
if (overrides["ssh-auth-sock"] == "")
|
||||
overrides["ssh-auth-sock"] = getEnv("SSH_AUTH_SOCK");
|
||||
writeInt(overrides.size(), to);
|
||||
for (auto & i : overrides) {
|
||||
writeString(i.first, to);
|
||||
writeString(i.second, to);
|
||||
}
|
||||
to << overrides.size();
|
||||
for (auto & i : overrides)
|
||||
to << i.first << i.second;
|
||||
}
|
||||
|
||||
processStderr();
|
||||
|
|
@ -179,8 +174,7 @@ void RemoteStore::setOptions()
|
|||
bool RemoteStore::isValidPath(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopIsValidPath, to);
|
||||
writeString(path, to);
|
||||
to << wopIsValidPath << path;
|
||||
processStderr();
|
||||
unsigned int reply = readInt(from);
|
||||
return reply != 0;
|
||||
|
|
@ -196,8 +190,7 @@ PathSet RemoteStore::queryValidPaths(const PathSet & paths)
|
|||
if (isValidPath(i)) res.insert(i);
|
||||
return res;
|
||||
} else {
|
||||
writeInt(wopQueryValidPaths, to);
|
||||
writeStrings(paths, to);
|
||||
to << wopQueryValidPaths << paths;
|
||||
processStderr();
|
||||
return readStorePaths<PathSet>(from);
|
||||
}
|
||||
|
|
@ -207,7 +200,7 @@ PathSet RemoteStore::queryValidPaths(const PathSet & paths)
|
|||
PathSet RemoteStore::queryAllValidPaths()
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryAllValidPaths, to);
|
||||
to << wopQueryAllValidPaths;
|
||||
processStderr();
|
||||
return readStorePaths<PathSet>(from);
|
||||
}
|
||||
|
|
@ -219,15 +212,13 @@ PathSet RemoteStore::querySubstitutablePaths(const PathSet & paths)
|
|||
if (GET_PROTOCOL_MINOR(daemonVersion) < 12) {
|
||||
PathSet res;
|
||||
for (auto & i : paths) {
|
||||
writeInt(wopHasSubstitutes, to);
|
||||
writeString(i, to);
|
||||
to << wopHasSubstitutes << i;
|
||||
processStderr();
|
||||
if (readInt(from)) res.insert(i);
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
writeInt(wopQuerySubstitutablePaths, to);
|
||||
writeStrings(paths, to);
|
||||
to << wopQuerySubstitutablePaths << paths;
|
||||
processStderr();
|
||||
return readStorePaths<PathSet>(from);
|
||||
}
|
||||
|
|
@ -247,8 +238,7 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
|
|||
|
||||
for (auto & i : paths) {
|
||||
SubstitutablePathInfo info;
|
||||
writeInt(wopQuerySubstitutablePathInfo, to);
|
||||
writeString(i, to);
|
||||
to << wopQuerySubstitutablePathInfo << i;
|
||||
processStderr();
|
||||
unsigned int reply = readInt(from);
|
||||
if (reply == 0) continue;
|
||||
|
|
@ -262,8 +252,7 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
|
|||
|
||||
} else {
|
||||
|
||||
writeInt(wopQuerySubstitutablePathInfos, to);
|
||||
writeStrings(paths, to);
|
||||
to << wopQuerySubstitutablePathInfos << paths;
|
||||
processStderr();
|
||||
unsigned int count = readInt(from);
|
||||
for (unsigned int n = 0; n < count; n++) {
|
||||
|
|
@ -283,8 +272,7 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
|
|||
ValidPathInfo RemoteStore::queryPathInfo(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryPathInfo, to);
|
||||
writeString(path, to);
|
||||
to << wopQueryPathInfo << path;
|
||||
processStderr();
|
||||
ValidPathInfo info;
|
||||
info.path = path;
|
||||
|
|
@ -301,8 +289,7 @@ ValidPathInfo RemoteStore::queryPathInfo(const Path & path)
|
|||
Hash RemoteStore::queryPathHash(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryPathHash, to);
|
||||
writeString(path, to);
|
||||
to << wopQueryPathHash << path;
|
||||
processStderr();
|
||||
string hash = readString(from);
|
||||
return parseHash(htSHA256, hash);
|
||||
|
|
@ -313,8 +300,7 @@ void RemoteStore::queryReferences(const Path & path,
|
|||
PathSet & references)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryReferences, to);
|
||||
writeString(path, to);
|
||||
to << wopQueryReferences << path;
|
||||
processStderr();
|
||||
PathSet references2 = readStorePaths<PathSet>(from);
|
||||
references.insert(references2.begin(), references2.end());
|
||||
|
|
@ -325,8 +311,7 @@ void RemoteStore::queryReferrers(const Path & path,
|
|||
PathSet & referrers)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryReferrers, to);
|
||||
writeString(path, to);
|
||||
to << wopQueryReferrers << path;
|
||||
processStderr();
|
||||
PathSet referrers2 = readStorePaths<PathSet>(from);
|
||||
referrers.insert(referrers2.begin(), referrers2.end());
|
||||
|
|
@ -336,8 +321,7 @@ void RemoteStore::queryReferrers(const Path & path,
|
|||
Path RemoteStore::queryDeriver(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryDeriver, to);
|
||||
writeString(path, to);
|
||||
to << wopQueryDeriver << path;
|
||||
processStderr();
|
||||
Path drvPath = readString(from);
|
||||
if (drvPath != "") assertStorePath(drvPath);
|
||||
|
|
@ -348,8 +332,7 @@ Path RemoteStore::queryDeriver(const Path & path)
|
|||
PathSet RemoteStore::queryValidDerivers(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryValidDerivers, to);
|
||||
writeString(path, to);
|
||||
to << wopQueryValidDerivers << path;
|
||||
processStderr();
|
||||
return readStorePaths<PathSet>(from);
|
||||
}
|
||||
|
|
@ -358,8 +341,7 @@ PathSet RemoteStore::queryValidDerivers(const Path & path)
|
|||
PathSet RemoteStore::queryDerivationOutputs(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryDerivationOutputs, to);
|
||||
writeString(path, to);
|
||||
to << wopQueryDerivationOutputs << path;
|
||||
processStderr();
|
||||
return readStorePaths<PathSet>(from);
|
||||
}
|
||||
|
|
@ -368,8 +350,7 @@ PathSet RemoteStore::queryDerivationOutputs(const Path & path)
|
|||
PathSet RemoteStore::queryDerivationOutputNames(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryDerivationOutputNames, to);
|
||||
writeString(path, to);
|
||||
to << wopQueryDerivationOutputNames << path;
|
||||
processStderr();
|
||||
return readStrings<PathSet>(from);
|
||||
}
|
||||
|
|
@ -378,8 +359,7 @@ PathSet RemoteStore::queryDerivationOutputNames(const Path & path)
|
|||
Path RemoteStore::queryPathFromHashPart(const string & hashPart)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryPathFromHashPart, to);
|
||||
writeString(hashPart, to);
|
||||
to << wopQueryPathFromHashPart << hashPart;
|
||||
processStderr();
|
||||
Path path = readString(from);
|
||||
if (!path.empty()) assertStorePath(path);
|
||||
|
|
@ -396,12 +376,10 @@ Path RemoteStore::addToStore(const string & name, const Path & _srcPath,
|
|||
|
||||
Path srcPath(absPath(_srcPath));
|
||||
|
||||
writeInt(wopAddToStore, to);
|
||||
writeString(name, to);
|
||||
/* backwards compatibility hack */
|
||||
writeInt((hashAlgo == htSHA256 && recursive) ? 0 : 1, to);
|
||||
writeInt(recursive ? 1 : 0, to);
|
||||
writeString(printHashType(hashAlgo), to);
|
||||
to << wopAddToStore << name
|
||||
<< ((hashAlgo == htSHA256 && recursive) ? 0 : 1) /* backwards compatibility hack */
|
||||
<< (recursive ? 1 : 0)
|
||||
<< printHashType(hashAlgo);
|
||||
|
||||
try {
|
||||
to.written = 0;
|
||||
|
|
@ -429,10 +407,7 @@ Path RemoteStore::addTextToStore(const string & name, const string & s,
|
|||
if (repair) throw Error("repairing is not supported when building through the Nix daemon");
|
||||
|
||||
openConnection();
|
||||
writeInt(wopAddTextToStore, to);
|
||||
writeString(name, to);
|
||||
writeString(s, to);
|
||||
writeStrings(references, to);
|
||||
to << wopAddTextToStore << name << s << references;
|
||||
|
||||
processStderr();
|
||||
return readStorePath(from);
|
||||
|
|
@ -443,9 +418,7 @@ void RemoteStore::exportPath(const Path & path, bool sign,
|
|||
Sink & sink)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopExportPath, to);
|
||||
writeString(path, to);
|
||||
writeInt(sign ? 1 : 0, to);
|
||||
to << wopExportPath << path << (sign ? 1 : 0);
|
||||
processStderr(&sink); /* sink receives the actual data */
|
||||
readInt(from);
|
||||
}
|
||||
|
|
@ -454,7 +427,7 @@ void RemoteStore::exportPath(const Path & path, bool sign,
|
|||
Paths RemoteStore::importPaths(bool requireSignature, Source & source)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopImportPaths, to);
|
||||
to << wopImportPaths;
|
||||
/* We ignore requireSignature, since the worker forces it to true
|
||||
anyway. */
|
||||
processStderr(0, &source);
|
||||
|
|
@ -466,16 +439,16 @@ void RemoteStore::buildPaths(const PathSet & drvPaths, BuildMode buildMode)
|
|||
{
|
||||
if (buildMode != bmNormal) throw Error("repairing or checking is not supported when building through the Nix daemon");
|
||||
openConnection();
|
||||
writeInt(wopBuildPaths, to);
|
||||
to << wopBuildPaths;
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 13)
|
||||
writeStrings(drvPaths, to);
|
||||
to << drvPaths;
|
||||
else {
|
||||
/* For backwards compatibility with old daemons, strip output
|
||||
identifiers. */
|
||||
PathSet drvPaths2;
|
||||
for (auto & i : drvPaths)
|
||||
drvPaths2.insert(string(i, 0, i.find('!')));
|
||||
writeStrings(drvPaths2, to);
|
||||
to << drvPaths2;
|
||||
}
|
||||
processStderr();
|
||||
readInt(from);
|
||||
|
|
@ -492,8 +465,7 @@ BuildResult RemoteStore::buildDerivation(const Path & drvPath, const BasicDeriva
|
|||
void RemoteStore::ensurePath(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopEnsurePath, to);
|
||||
writeString(path, to);
|
||||
to << wopEnsurePath << path;
|
||||
processStderr();
|
||||
readInt(from);
|
||||
}
|
||||
|
|
@ -502,8 +474,7 @@ void RemoteStore::ensurePath(const Path & path)
|
|||
void RemoteStore::addTempRoot(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopAddTempRoot, to);
|
||||
writeString(path, to);
|
||||
to << wopAddTempRoot << path;
|
||||
processStderr();
|
||||
readInt(from);
|
||||
}
|
||||
|
|
@ -512,8 +483,7 @@ void RemoteStore::addTempRoot(const Path & path)
|
|||
void RemoteStore::addIndirectRoot(const Path & path)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopAddIndirectRoot, to);
|
||||
writeString(path, to);
|
||||
to << wopAddIndirectRoot << path;
|
||||
processStderr();
|
||||
readInt(from);
|
||||
}
|
||||
|
|
@ -522,7 +492,7 @@ void RemoteStore::addIndirectRoot(const Path & path)
|
|||
void RemoteStore::syncWithGC()
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopSyncWithGC, to);
|
||||
to << wopSyncWithGC;
|
||||
processStderr();
|
||||
readInt(from);
|
||||
}
|
||||
|
|
@ -531,7 +501,7 @@ void RemoteStore::syncWithGC()
|
|||
Roots RemoteStore::findRoots()
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopFindRoots, to);
|
||||
to << wopFindRoots;
|
||||
processStderr();
|
||||
unsigned int count = readInt(from);
|
||||
Roots result;
|
||||
|
|
@ -548,17 +518,11 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
|||
{
|
||||
openConnection(false);
|
||||
|
||||
writeInt(wopCollectGarbage, to);
|
||||
writeInt(options.action, to);
|
||||
writeStrings(options.pathsToDelete, to);
|
||||
writeInt(options.ignoreLiveness, to);
|
||||
writeLongLong(options.maxFreed, to);
|
||||
writeInt(0, to);
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 5) {
|
||||
to << wopCollectGarbage << options.action << options.pathsToDelete << options.ignoreLiveness
|
||||
<< options.maxFreed << 0;
|
||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 5)
|
||||
/* removed options */
|
||||
writeInt(0, to);
|
||||
writeInt(0, to);
|
||||
}
|
||||
to << 0 << 0;
|
||||
|
||||
processStderr();
|
||||
|
||||
|
|
@ -571,7 +535,7 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
|||
PathSet RemoteStore::queryFailedPaths()
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopQueryFailedPaths, to);
|
||||
to << wopQueryFailedPaths;
|
||||
processStderr();
|
||||
return readStorePaths<PathSet>(from);
|
||||
}
|
||||
|
|
@ -580,8 +544,7 @@ PathSet RemoteStore::queryFailedPaths()
|
|||
void RemoteStore::clearFailedPaths(const PathSet & paths)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopClearFailedPaths, to);
|
||||
writeStrings(paths, to);
|
||||
to << wopClearFailedPaths << paths;
|
||||
processStderr();
|
||||
readInt(from);
|
||||
}
|
||||
|
|
@ -589,7 +552,7 @@ void RemoteStore::clearFailedPaths(const PathSet & paths)
|
|||
void RemoteStore::optimiseStore()
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopOptimiseStore, to);
|
||||
to << wopOptimiseStore;
|
||||
processStderr();
|
||||
readInt(from);
|
||||
}
|
||||
|
|
@ -597,9 +560,7 @@ void RemoteStore::optimiseStore()
|
|||
bool RemoteStore::verifyStore(bool checkContents, bool repair)
|
||||
{
|
||||
openConnection();
|
||||
writeInt(wopVerifyStore, to);
|
||||
writeInt(checkContents, to);
|
||||
writeInt(repair, to);
|
||||
to << wopVerifyStore << checkContents << repair;
|
||||
processStderr();
|
||||
return readInt(from) != 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -298,10 +298,10 @@ void exportPaths(StoreAPI & store, const Paths & paths,
|
|||
bool sign, Sink & sink)
|
||||
{
|
||||
for (auto & i : paths) {
|
||||
writeInt(1, sink);
|
||||
sink << 1;
|
||||
store.exportPath(i, sign, sink);
|
||||
}
|
||||
writeInt(0, sink);
|
||||
sink << 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue