mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Merge pull request #12985 from NixOS/mergify/bp/2.28-maintenance/pr-12984
Fix `;` and `#` bug in machine file parsing (backport #12984)
This commit is contained in:
commit
bb8af4ceb7
2 changed files with 31 additions and 17 deletions
|
@ -73,6 +73,18 @@ TEST(machines, getMachinesWithSemicolonSeparator) {
|
||||||
EXPECT_THAT(actual, Contains(Field(&Machine::storeUri, AuthorityMatches("nix@itchy.labs.cs.uu.nl"))));
|
EXPECT_THAT(actual, Contains(Field(&Machine::storeUri, AuthorityMatches("nix@itchy.labs.cs.uu.nl"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(machines, getMachinesWithCommentsAndSemicolonSeparator) {
|
||||||
|
auto actual = Machine::parseConfig({},
|
||||||
|
"# This is a comment ; this is still that comment\n"
|
||||||
|
"nix@scratchy.labs.cs.uu.nl ; nix@itchy.labs.cs.uu.nl\n"
|
||||||
|
"# This is also a comment ; this also is still that comment\n"
|
||||||
|
"nix@scabby.labs.cs.uu.nl\n");
|
||||||
|
EXPECT_THAT(actual, SizeIs(3));
|
||||||
|
EXPECT_THAT(actual, Contains(Field(&Machine::storeUri, AuthorityMatches("nix@scratchy.labs.cs.uu.nl"))));
|
||||||
|
EXPECT_THAT(actual, Contains(Field(&Machine::storeUri, AuthorityMatches("nix@itchy.labs.cs.uu.nl"))));
|
||||||
|
EXPECT_THAT(actual, Contains(Field(&Machine::storeUri, AuthorityMatches("nix@scabby.labs.cs.uu.nl"))));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(machines, getMachinesWithCorrectCompleteSingleBuilder) {
|
TEST(machines, getMachinesWithCorrectCompleteSingleBuilder) {
|
||||||
auto actual = Machine::parseConfig({},
|
auto actual = Machine::parseConfig({},
|
||||||
"nix@scratchy.labs.cs.uu.nl i686-linux "
|
"nix@scratchy.labs.cs.uu.nl i686-linux "
|
||||||
|
|
|
@ -105,13 +105,14 @@ ref<Store> Machine::openStore() const
|
||||||
static std::vector<std::string> expandBuilderLines(const std::string & builders)
|
static std::vector<std::string> expandBuilderLines(const std::string & builders)
|
||||||
{
|
{
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
for (auto line : tokenizeString<std::vector<std::string>>(builders, "\n;")) {
|
for (auto line : tokenizeString<std::vector<std::string>>(builders, "\n")) {
|
||||||
trim(line);
|
trim(line);
|
||||||
line.erase(std::find(line.begin(), line.end(), '#'), line.end());
|
line.erase(std::find(line.begin(), line.end(), '#'), line.end());
|
||||||
if (line.empty()) continue;
|
for (auto entry : tokenizeString<std::vector<std::string>>(line, ";")) {
|
||||||
|
if (entry.empty()) continue;
|
||||||
|
|
||||||
if (line[0] == '@') {
|
if (entry[0] == '@') {
|
||||||
const std::string path = trim(std::string(line, 1));
|
const std::string path = trim(std::string(entry, 1));
|
||||||
std::string text;
|
std::string text;
|
||||||
try {
|
try {
|
||||||
text = readFile(path);
|
text = readFile(path);
|
||||||
|
@ -119,14 +120,15 @@ static std::vector<std::string> expandBuilderLines(const std::string & builders)
|
||||||
if (e.errNo != ENOENT)
|
if (e.errNo != ENOENT)
|
||||||
throw;
|
throw;
|
||||||
debug("cannot find machines file '%s'", path);
|
debug("cannot find machines file '%s'", path);
|
||||||
}
|
|
||||||
|
|
||||||
const auto lines = expandBuilderLines(text);
|
|
||||||
result.insert(end(result), begin(lines), end(lines));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.emplace_back(line);
|
const auto entrys = expandBuilderLines(text);
|
||||||
|
result.insert(end(result), begin(entrys), end(entrys));
|
||||||
|
} else {
|
||||||
|
result.emplace_back(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue