aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/remote-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2011-12-16 23:33:01 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2011-12-16 23:33:01 +0000
commit194d21f9f63ceb034f3e8294f89aa6bf6a217bc9 (patch)
tree7eb6da5955482a82f4d34b60dcb10514a4a55f59 /src/libstore/remote-store.cc
parent3c3107da86ff71a08ce44027ee5899acf486796a (diff)
parent273b288a7e862ac1918064537ff130cc751fa9fd (diff)
* Sync with the trunk.
Diffstat (limited to 'src/libstore/remote-store.cc')
-rw-r--r--src/libstore/remote-store.cc51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 84c87246f..ce99c205e 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -27,13 +27,15 @@ Path readStorePath(Source & from)
}
-PathSet readStorePaths(Source & from)
+template<class T> T readStorePaths(Source & from)
{
- PathSet paths = readStringSet(from);
- foreach (PathSet::iterator, i, paths) assertStorePath(*i);
+ T paths = readStrings<T>(from);
+ foreach (typename T::iterator, i, paths) assertStorePath(*i);
return paths;
}
+template PathSet readStorePaths(Source & from);
+
RemoteStore::RemoteStore()
{
@@ -65,6 +67,7 @@ void RemoteStore::openConnection()
/* Send the magic greeting, check for the reply. */
try {
writeInt(WORKER_MAGIC_1, to);
+ to.flush();
unsigned int magic = readInt(from);
if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
@@ -166,6 +169,7 @@ void RemoteStore::connectToDaemon()
RemoteStore::~RemoteStore()
{
try {
+ to.flush();
fdSocket.close();
if (child != -1)
child.wait(true);
@@ -213,7 +217,7 @@ PathSet RemoteStore::queryValidPaths()
openConnection();
writeInt(wopQueryValidPaths, to);
processStderr();
- return readStorePaths(from);
+ return readStorePaths<PathSet>(from);
}
@@ -240,7 +244,7 @@ bool RemoteStore::querySubstitutablePathInfo(const Path & path,
if (reply == 0) return false;
info.deriver = readString(from);
if (info.deriver != "") assertStorePath(info.deriver);
- info.references = readStorePaths(from);
+ info.references = readStorePaths<PathSet>(from);
info.downloadSize = readLongLong(from);
info.narSize = GET_PROTOCOL_MINOR(daemonVersion) >= 7 ? readLongLong(from) : 0;
return true;
@@ -258,7 +262,7 @@ ValidPathInfo RemoteStore::queryPathInfo(const Path & path)
info.deriver = readString(from);
if (info.deriver != "") assertStorePath(info.deriver);
info.hash = parseHash(htSHA256, readString(from));
- info.references = readStorePaths(from);
+ info.references = readStorePaths<PathSet>(from);
info.registrationTime = readInt(from);
info.narSize = readLongLong(from);
return info;
@@ -283,7 +287,7 @@ void RemoteStore::queryReferences(const Path & path,
writeInt(wopQueryReferences, to);
writeString(path, to);
processStderr();
- PathSet references2 = readStorePaths(from);
+ PathSet references2 = readStorePaths<PathSet>(from);
references.insert(references2.begin(), references2.end());
}
@@ -295,7 +299,7 @@ void RemoteStore::queryReferrers(const Path & path,
writeInt(wopQueryReferrers, to);
writeString(path, to);
processStderr();
- PathSet referrers2 = readStorePaths(from);
+ PathSet referrers2 = readStorePaths<PathSet>(from);
referrers.insert(referrers2.begin(), referrers2.end());
}
@@ -318,7 +322,7 @@ PathSet RemoteStore::queryDerivationOutputs(const Path & path)
writeInt(wopQueryDerivationOutputs, to);
writeString(path, to);
processStderr();
- return readStorePaths(from);
+ return readStorePaths<PathSet>(from);
}
@@ -338,7 +342,7 @@ Path RemoteStore::addToStore(const Path & _srcPath,
openConnection();
Path srcPath(absPath(_srcPath));
-
+
writeInt(wopAddToStore, to);
writeString(baseNameOf(srcPath), to);
/* backwards compatibility hack */
@@ -358,7 +362,7 @@ Path RemoteStore::addTextToStore(const string & name, const string & s,
writeInt(wopAddTextToStore, to);
writeString(name, to);
writeString(s, to);
- writeStringSet(references, to);
+ writeStrings(references, to);
processStderr();
return readStorePath(from);
@@ -377,14 +381,14 @@ void RemoteStore::exportPath(const Path & path, bool sign,
}
-Path RemoteStore::importPath(bool requireSignature, Source & source)
+Paths RemoteStore::importPaths(bool requireSignature, Source & source)
{
openConnection();
- writeInt(wopImportPath, to);
+ writeInt(wopImportPaths, to);
/* We ignore requireSignature, since the worker forces it to true
- anyway. */
+ anyway. */
processStderr(0, &source);
- return readStorePath(from);
+ return readStorePaths<Paths>(from);
}
@@ -392,7 +396,7 @@ void RemoteStore::buildDerivations(const PathSet & drvPaths)
{
openConnection();
writeInt(wopBuildDerivations, to);
- writeStringSet(drvPaths, to);
+ writeStrings(drvPaths, to);
processStderr();
readInt(from);
}
@@ -459,7 +463,7 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
writeInt(wopCollectGarbage, to);
writeInt(options.action, to);
- writeStringSet(options.pathsToDelete, to);
+ writeStrings(options.pathsToDelete, to);
writeInt(options.ignoreLiveness, to);
writeLongLong(options.maxFreed, to);
writeInt(options.maxLinks, to);
@@ -471,7 +475,7 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
processStderr();
- results.paths = readStringSet(from);
+ results.paths = readStrings<PathSet>(from);
results.bytesFreed = readLongLong(from);
results.blocksFreed = readLongLong(from);
}
@@ -482,7 +486,7 @@ PathSet RemoteStore::queryFailedPaths()
openConnection();
writeInt(wopQueryFailedPaths, to);
processStderr();
- return readStorePaths(from);
+ return readStorePaths<PathSet>(from);
}
@@ -490,7 +494,7 @@ void RemoteStore::clearFailedPaths(const PathSet & paths)
{
openConnection();
writeInt(wopClearFailedPaths, to);
- writeStringSet(paths, to);
+ writeStrings(paths, to);
processStderr();
readInt(from);
}
@@ -498,6 +502,7 @@ void RemoteStore::clearFailedPaths(const PathSet & paths)
void RemoteStore::processStderr(Sink * sink, Source * source)
{
+ to.flush();
unsigned int msg;
while ((msg = readInt(from)) == STDERR_NEXT
|| msg == STDERR_READ || msg == STDERR_WRITE) {
@@ -508,11 +513,11 @@ void RemoteStore::processStderr(Sink * sink, Source * source)
}
else if (msg == STDERR_READ) {
if (!source) throw Error("no source");
- unsigned int len = readInt(from);
+ size_t len = readInt(from);
unsigned char * buf = new unsigned char[len];
AutoDeleteArray<unsigned char> d(buf);
- (*source)(buf, len);
- writeString(string((const char *) buf, len), to);
+ writeString(buf, source->read(buf, len), to);
+ to.flush();
}
else {
string s = readString(from);