From 28db29786277ce6790ffb1567f9e679c62737b96 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 10 Jan 2017 10:36:26 -0500 Subject: build-remote: Don't use C++ streams to read the conf file --- src/build-remote/build-remote.cc | 58 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index cf1062636..98ccc3ddc 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -1,8 +1,6 @@ #include #include #include -#include -#include #include #include #include @@ -71,35 +69,37 @@ static std::vector read_conf() { auto conf = getEnv("NIX_REMOTE_SYSTEMS", SYSCONFDIR "/nix/machines"); auto machines = std::vector{}; - auto confFile = std::ifstream{conf}; - if (confFile.good()) { - confFile.exceptions(std::ifstream::badbit); - for (string line; getline(confFile, line);) { - chomp(line); - line.erase(std::find(line.begin(), line.end(), '#'), line.end()); - if (line.empty()) { - continue; - } - auto tokens = tokenizeString>(line); - auto sz = tokens.size(); - if (sz < 4) { - throw new FormatError(format("Bad machines.conf file %1%") - % conf); - } - machines.emplace_back(tokens[0], - tokenizeString>(tokens[1], ","), - tokens[2], - stoull(tokens[3]), - sz >= 5 ? stoull(tokens[4]) : 1LL, - sz >= 6 ? - tokenizeString>(tokens[5], ",") : - std::set{}, - sz >= 7 ? - tokenizeString>(tokens[6], ",") : - std::set{}); + auto lines = std::vector{}; + try { + lines = tokenizeString>(readFile(conf), "\n"); + } catch (const SysError & e) { + if (e.errNo != ENOENT) + throw; + } + for (auto line : lines) { + chomp(line); + line.erase(std::find(line.begin(), line.end(), '#'), line.end()); + if (line.empty()) { + continue; + } + auto tokens = tokenizeString>(line); + auto sz = tokens.size(); + if (sz < 4) { + throw new FormatError(format("Bad machines.conf file %1%") + % conf); } + machines.emplace_back(tokens[0], + tokenizeString>(tokens[1], ","), + tokens[2], + stoull(tokens[3]), + sz >= 5 ? stoull(tokens[4]) : 1LL, + sz >= 6 ? + tokenizeString>(tokens[5], ",") : + std::set{}, + sz >= 7 ? + tokenizeString>(tokens[6], ",") : + std::set{}); } - confFile.close(); return machines; } -- cgit v1.2.3