config: variables update their value when set again (#4263)

* variables update their value when set again

* only sort if new variable is found

* clang-format
This commit is contained in:
flicko 2024-01-02 21:08:30 +05:30 committed by GitHub
parent 3c33d4b9dd
commit 4f26c4e1eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -395,10 +395,20 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
if (!COMMAND.starts_with("device:") /* devices parsed later */ && !COMMAND.starts_with("plugin:") /* plugins parsed later */) {
if (COMMAND[0] == '$') {
// register a dynamic var
bool found = false;
for (auto& [var, val] : configDynamicVars) {
if (var == COMMAND.substr(1)) {
Debug::log(LOG, "Registered new value for dynamic var \"{}\" -> {}", COMMAND, VALUE);
val = VALUE;
found = true;
}
}
if (!found) {
Debug::log(LOG, "Registered dynamic var \"{}\" -> {}", COMMAND, VALUE);
configDynamicVars.emplace_back(std::make_pair<>(COMMAND.substr(1), VALUE));
std::sort(configDynamicVars.begin(), configDynamicVars.end(), [&](const auto& a, const auto& b) { return a.first.length() > b.first.length(); });
}
} else {
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">: No such field.";
}