mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
Style
This commit is contained in:
parent
6e30d9b69f
commit
e6795c4350
1 changed files with 24 additions and 18 deletions
|
@ -39,7 +39,8 @@ Machine::Machine(decltype(storeUri) storeUri,
|
||||||
sshPublicHostKey(sshPublicHostKey)
|
sshPublicHostKey(sshPublicHostKey)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool Machine::allSupported(const std::set<string> & features) const {
|
bool Machine::allSupported(const std::set<string> & features) const
|
||||||
|
{
|
||||||
return std::all_of(features.begin(), features.end(),
|
return std::all_of(features.begin(), features.end(),
|
||||||
[&](const string & feature) {
|
[&](const string & feature) {
|
||||||
return supportedFeatures.count(feature) ||
|
return supportedFeatures.count(feature) ||
|
||||||
|
@ -47,14 +48,16 @@ bool Machine::allSupported(const std::set<string> & features) const {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Machine::mandatoryMet(const std::set<string> & features) const {
|
bool Machine::mandatoryMet(const std::set<string> & features) const
|
||||||
|
{
|
||||||
return std::all_of(mandatoryFeatures.begin(), mandatoryFeatures.end(),
|
return std::all_of(mandatoryFeatures.begin(), mandatoryFeatures.end(),
|
||||||
[&](const string & feature) {
|
[&](const string & feature) {
|
||||||
return features.count(feature);
|
return features.count(feature);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ref<Store> Machine::openStore() const {
|
ref<Store> Machine::openStore() const
|
||||||
|
{
|
||||||
Store::Params storeParams;
|
Store::Params storeParams;
|
||||||
if (hasPrefix(storeUri, "ssh://")) {
|
if (hasPrefix(storeUri, "ssh://")) {
|
||||||
storeParams["max-connections"] = "1";
|
storeParams["max-connections"] = "1";
|
||||||
|
@ -83,7 +86,8 @@ ref<Store> Machine::openStore() const {
|
||||||
return nix::openStore(storeUri, storeParams);
|
return nix::openStore(storeUri, storeParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
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<string>>(builders, "\n;")) {
|
for (auto line : tokenizeString<std::vector<string>>(builders, "\n;")) {
|
||||||
trim(line);
|
trim(line);
|
||||||
|
@ -111,7 +115,8 @@ static std::vector<std::string> expandBuilderLines(const std::string& builders)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Machine parseBuilderLine(const std::string& line) {
|
static Machine parseBuilderLine(const std::string & line)
|
||||||
|
{
|
||||||
const auto tokens = tokenizeString<std::vector<string>>(line);
|
const auto tokens = tokenizeString<std::vector<string>>(line);
|
||||||
|
|
||||||
auto isSet = [&](size_t fieldIndex) {
|
auto isSet = [&](size_t fieldIndex) {
|
||||||
|
@ -127,27 +132,28 @@ static Machine parseBuilderLine(const std::string& line) {
|
||||||
};
|
};
|
||||||
|
|
||||||
auto ensureBase64 = [&](size_t fieldIndex) {
|
auto ensureBase64 = [&](size_t fieldIndex) {
|
||||||
const auto& str = tokens[fieldIndex];
|
const auto & str = tokens[fieldIndex];
|
||||||
try {
|
try {
|
||||||
base64Decode(str);
|
base64Decode(str);
|
||||||
} catch (const Error& e) {
|
} catch (const Error & e) {
|
||||||
throw FormatError("bad machine specification: a column #%lu in a row: '%s' is not valid base64 string: %s", fieldIndex, line, e.what());
|
throw FormatError("bad machine specification: a column #%lu in a row: '%s' is not valid base64 string: %s", fieldIndex, line, e.what());
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isSet(0)) {
|
if (!isSet(0))
|
||||||
throw FormatError("bad machine specification: store URI was not found at the first column of a row: '%s'", line);
|
throw FormatError("bad machine specification: store URL was not found at the first column of a row: '%s'", line);
|
||||||
}
|
|
||||||
|
|
||||||
return {tokens[0],
|
return {
|
||||||
isSet(1) ? tokenizeString<std::vector<string>>(tokens[1], ",") : std::vector<string>{settings.thisSystem},
|
tokens[0],
|
||||||
isSet(2) ? tokens[2] : "",
|
isSet(1) ? tokenizeString<std::vector<string>>(tokens[1], ",") : std::vector<string>{settings.thisSystem},
|
||||||
isSet(3) ? parseUnsignedIntField(3) : 1U,
|
isSet(2) ? tokens[2] : "",
|
||||||
isSet(4) ? parseUnsignedIntField(4) : 1U,
|
isSet(3) ? parseUnsignedIntField(3) : 1U,
|
||||||
isSet(5) ? tokenizeString<std::set<string>>(tokens[5], ",") : std::set<string>{},
|
isSet(4) ? parseUnsignedIntField(4) : 1U,
|
||||||
isSet(6) ? tokenizeString<std::set<string>>(tokens[6], ",") : std::set<string>{},
|
isSet(5) ? tokenizeString<std::set<string>>(tokens[5], ",") : std::set<string>{},
|
||||||
isSet(7) ? ensureBase64(7) : ""};
|
isSet(6) ? tokenizeString<std::set<string>>(tokens[6], ",") : std::set<string>{},
|
||||||
|
isSet(7) ? ensureBase64(7) : ""
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static Machines parseBuilderLines(const std::vector<std::string>& builders) {
|
static Machines parseBuilderLines(const std::vector<std::string>& builders) {
|
||||||
|
|
Loading…
Reference in a new issue