* Better error checking of the data from the substituters.

This commit is contained in:
Eelco Dolstra 2008-08-05 10:57:53 +00:00
parent 339c142009
commit 98b07466fb

View file

@ -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) bool LocalStore::hasSubstitutes(const Path & path)
{ {
foreach (Paths::iterator, i, substituters) { foreach (Paths::iterator, i, substituters) {
@ -528,13 +538,7 @@ bool LocalStore::hasSubstitutes(const Path & path)
*run.to << "have\n" << path << "\n" << std::flush; *run.to << "have\n" << path << "\n" << std::flush;
string s; if (getIntLine<int>(*run.from)) return true;
int res;
getline(*run.from, s);
if (!string2Int(s, res)) abort();
if (res) return true;
} }
return false; return false;
@ -549,26 +553,17 @@ bool LocalStore::querySubstitutablePathInfo(const Path & substituter,
*run.to << "info\n" << path << "\n" << std::flush; *run.to << "info\n" << path << "\n" << std::flush;
string s; if (!getIntLine<int>(*run.from)) return false;
int res;
getline(*run.from, s);
if (!string2Int(s, res)) abort();
if (!res) return false;
getline(*run.from, info.deriver); getline(*run.from, info.deriver);
int nrRefs; if (info.deriver != "") assertStorePath(info.deriver);
getline(*run.from, s); int nrRefs = getIntLine<int>(*run.from);
if (!string2Int(s, nrRefs)) abort();
while (nrRefs--) { while (nrRefs--) {
Path p; getline(*run.from, p); Path p; getline(*run.from, p);
assertStorePath(p);
info.references.insert(p); info.references.insert(p);
} }
getline(*run.from, s); info.downloadSize = getIntLine<long long>(*run.from);
long long size;
if (!string2Int(s, size)) abort();
info.downloadSize = size;
return true; return true;
} }