build-remote: Don't use C++ streams to read the conf file

This commit is contained in:
Shea Levy 2017-01-10 10:36:26 -05:00
parent d771c28613
commit 28db297862

View file

@ -1,8 +1,6 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#include <fstream>
#include <sstream>
#include <set> #include <set>
#include <memory> #include <memory>
#include <tuple> #include <tuple>
@ -71,10 +69,14 @@ static std::vector<machine> read_conf() {
auto conf = getEnv("NIX_REMOTE_SYSTEMS", SYSCONFDIR "/nix/machines"); auto conf = getEnv("NIX_REMOTE_SYSTEMS", SYSCONFDIR "/nix/machines");
auto machines = std::vector<machine>{}; auto machines = std::vector<machine>{};
auto confFile = std::ifstream{conf}; auto lines = std::vector<string>{};
if (confFile.good()) { try {
confFile.exceptions(std::ifstream::badbit); lines = tokenizeString<std::vector<string>>(readFile(conf), "\n");
for (string line; getline(confFile, line);) { } catch (const SysError & e) {
if (e.errNo != ENOENT)
throw;
}
for (auto line : lines) {
chomp(line); chomp(line);
line.erase(std::find(line.begin(), line.end(), '#'), line.end()); line.erase(std::find(line.begin(), line.end(), '#'), line.end());
if (line.empty()) { if (line.empty()) {
@ -98,8 +100,6 @@ static std::vector<machine> read_conf() {
tokenizeString<std::set<string>>(tokens[6], ",") : tokenizeString<std::set<string>>(tokens[6], ",") :
std::set<string>{}); std::set<string>{});
} }
}
confFile.close();
return machines; return machines;
} }