bugfix: expanding wildcards in config includes (#4354)
This commit is contained in:
@ -35,7 +35,8 @@ class Config {
|
|||||||
void setupConfig(Json::Value &dst, const std::string &config_file, int depth);
|
void setupConfig(Json::Value &dst, const std::string &config_file, int depth);
|
||||||
void resolveConfigIncludes(Json::Value &config, int depth);
|
void resolveConfigIncludes(Json::Value &config, int depth);
|
||||||
void mergeConfig(Json::Value &a_config_, Json::Value &b_config_);
|
void mergeConfig(Json::Value &a_config_, Json::Value &b_config_);
|
||||||
static std::optional<std::string> findIncludePath(const std::string &name);
|
static std::vector<std::string> findIncludePath(
|
||||||
|
const std::string &name, const std::vector<std::string> &dirs = CONFIG_DIRS);
|
||||||
|
|
||||||
std::string config_file_;
|
std::string config_file_;
|
||||||
|
|
||||||
|
@ -106,12 +106,24 @@ void Config::setupConfig(Json::Value &dst, const std::string &config_file, int d
|
|||||||
mergeConfig(dst, tmp_config);
|
mergeConfig(dst, tmp_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> Config::findIncludePath(const std::string &name) {
|
std::vector<std::string> Config::findIncludePath(const std::string &name,
|
||||||
|
const std::vector<std::string> &dirs) {
|
||||||
auto match1 = tryExpandPath(name, "");
|
auto match1 = tryExpandPath(name, "");
|
||||||
if (!match1.empty()) {
|
if (!match1.empty()) {
|
||||||
return match1.front();
|
return match1;
|
||||||
}
|
}
|
||||||
return findConfigPath({name});
|
if (const char *dir = std::getenv(Config::CONFIG_PATH_ENV)) {
|
||||||
|
if (auto res = tryExpandPath(dir, name); !res.empty()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto &dir : dirs) {
|
||||||
|
if (auto res = tryExpandPath(dir, name); !res.empty()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::resolveConfigIncludes(Json::Value &config, int depth) {
|
void Config::resolveConfigIncludes(Json::Value &config, int depth) {
|
||||||
@ -119,18 +131,22 @@ void Config::resolveConfigIncludes(Json::Value &config, int depth) {
|
|||||||
if (includes.isArray()) {
|
if (includes.isArray()) {
|
||||||
for (const auto &include : includes) {
|
for (const auto &include : includes) {
|
||||||
spdlog::info("Including resource file: {}", include.asString());
|
spdlog::info("Including resource file: {}", include.asString());
|
||||||
auto match = findIncludePath(include.asString());
|
auto matches = findIncludePath(include.asString());
|
||||||
if (match.has_value()) {
|
if (!matches.empty()) {
|
||||||
setupConfig(config, match.value(), depth + 1);
|
for (const auto &match : matches) {
|
||||||
|
setupConfig(config, match, depth + 1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
spdlog::warn("Unable to find resource file: {}", include.asString());
|
spdlog::warn("Unable to find resource file: {}", include.asString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (includes.isString()) {
|
} else if (includes.isString()) {
|
||||||
spdlog::info("Including resource file: {}", includes.asString());
|
spdlog::info("Including resource file: {}", includes.asString());
|
||||||
auto match = findIncludePath(includes.asString());
|
auto matches = findIncludePath(includes.asString());
|
||||||
if (match.has_value()) {
|
if (!matches.empty()) {
|
||||||
setupConfig(config, match.value(), depth + 1);
|
for (const auto &match : matches) {
|
||||||
|
setupConfig(config, match, depth + 1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
spdlog::warn("Unable to find resource file: {}", includes.asString());
|
spdlog::warn("Unable to find resource file: {}", includes.asString());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user