From 4f26c4e1ebf868243dc628182c88d7feb52c8472 Mon Sep 17 00:00:00 2001 From: flicko <77581181+flick0@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:08:30 +0530 Subject: [PATCH] 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 --- src/config/ConfigManager.cpp | 16 +++++++++++++--- 1 file 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."; }