diff options
-rw-r--r-- | src/config/ConfigManager.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 28959128..44b5374b 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -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 - Debug::log(LOG, "Registered dynamic var \"{}\" -> {}", COMMAND, VALUE); - configDynamicVars.emplace_back(std::make_pair<>(COMMAND.substr(1), VALUE)); + 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; + } + } - std::sort(configDynamicVars.begin(), configDynamicVars.end(), [&](const auto& a, const auto& b) { return a.first.length() > b.first.length(); }); + 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."; } |