From ef80a69399d1a5139dd29b77434a750d3da0650c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 18 Mar 2023 14:57:59 +0000 Subject: [PATCH] config: fix long variables being substrd --- src/config/ConfigManager.cpp | 14 +++++++++----- src/config/ConfigManager.hpp | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 3c75dc85..e261d699 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -40,11 +40,13 @@ CConfigManager::CConfigManager() { void CConfigManager::populateEnvironment() { environmentVariables.clear(); for (char** env = environ; *env; ++env) { - const std::string ENVVAR = *env; - const auto VARIABLE = ENVVAR.substr(0, ENVVAR.find_first_of('=')); - const auto VALUE = ENVVAR.substr(ENVVAR.find_first_of('=') + 1); - environmentVariables[VARIABLE] = VALUE; + const std::string ENVVAR = *env; + const auto VARIABLE = ENVVAR.substr(0, ENVVAR.find_first_of('=')); + const auto VALUE = ENVVAR.substr(ENVVAR.find_first_of('=') + 1); + environmentVariables.emplace_back(std::make_pair<>(VARIABLE, VALUE)); } + + std::sort(environmentVariables.begin(), environmentVariables.end(), [&](const auto& a, const auto& b) { return a.first.length() > b.first.length(); }); } void CConfigManager::setDefaultVars() { @@ -293,7 +295,9 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s if (COMMAND[0] == '$') { // register a dynamic var Debug::log(LOG, "Registered dynamic var \"%s\" -> %s", COMMAND.c_str(), VALUE.c_str()); - configDynamicVars[COMMAND.substr(1)] = 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."; } diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index fd6b40af..f09241f8 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -187,7 +187,7 @@ class CConfigManager { private: std::deque configPaths; // stores all the config paths std::unordered_map configModifyTimes; // stores modify times - std::unordered_map configDynamicVars; // stores dynamic vars declared by the user + std::vector> configDynamicVars; // stores dynamic vars declared by the user std::unordered_map configValues; std::unordered_map> deviceConfigs; // stores device configs @@ -215,7 +215,7 @@ class CConfigManager { bool firstExecDispatched = false; std::deque firstExecRequests; - std::unordered_map environmentVariables; + std::vector> environmentVariables; // internal methods void setDefaultVars();