aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-08-05 10:57:53 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-08-05 10:57:53 +0000
commit98b07466fbb9fc736bba0b93731117fd650e7349 (patch)
tree4de966345c0351c2f6108d0da4dcdedf4765a8e8 /src
parent339c1420096c254b20b5b16b79a075b2c646ee70 (diff)
* Better error checking of the data from the substituters.
Diffstat (limited to 'src')
-rw-r--r--src/libstore/local-store.cc37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index ccf1a51bc..d8ac9820f 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -520,6 +520,16 @@ void LocalStore::startSubstituter(const Path & substituter, RunningSubstituter &
}
+template<class T> T getIntLine(std::istream & str)
+{
+ string s;
+ T res;
+ getline(str, s);
+ if (!str || !string2Int(s, res)) throw Error("integer expected from stream");
+ return res;
+}
+
+
bool LocalStore::hasSubstitutes(const Path & path)
{
foreach (Paths::iterator, i, substituters) {
@@ -528,13 +538,7 @@ bool LocalStore::hasSubstitutes(const Path & path)
*run.to << "have\n" << path << "\n" << std::flush;
- string s;
-
- int res;
- getline(*run.from, s);
- if (!string2Int(s, res)) abort();
-
- if (res) return true;
+ if (getIntLine<int>(*run.from)) return true;
}
return false;
@@ -549,26 +553,17 @@ bool LocalStore::querySubstitutablePathInfo(const Path & substituter,
*run.to << "info\n" << path << "\n" << std::flush;
- string s;
-
- int res;
- getline(*run.from, s);
- if (!string2Int(s, res)) abort();
-
- if (!res) return false;
+ if (!getIntLine<int>(*run.from)) return false;
getline(*run.from, info.deriver);
- int nrRefs;
- getline(*run.from, s);
- if (!string2Int(s, nrRefs)) abort();
+ if (info.deriver != "") assertStorePath(info.deriver);
+ int nrRefs = getIntLine<int>(*run.from);
while (nrRefs--) {
Path p; getline(*run.from, p);
+ assertStorePath(p);
info.references.insert(p);
}
- getline(*run.from, s);
- long long size;
- if (!string2Int(s, size)) abort();
- info.downloadSize = size;
+ info.downloadSize = getIntLine<long long>(*run.from);
return true;
}