diff options
author | memchr <[email protected]> | 2023-09-12 11:54:05 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2023-09-12 12:54:05 +0100 |
commit | 5cc53c14d9d904fe9b97e72ed974bbea9d68eb64 (patch) | |
tree | ce0345cb58b319d949cf00f7324fc6c8b9c72dea | |
parent | 9192b20b96b56bbc4f8f6cf90e38375052fb4ff0 (diff) | |
download | Hyprland-5cc53c14d9d904fe9b97e72ed974bbea9d68eb64.tar.gz Hyprland-5cc53c14d9d904fe9b97e72ed974bbea9d68eb64.zip |
config: add wildcard handling in source= (#3276)
-rw-r--r-- | src/config/ConfigManager.cpp | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 7ebbb057..08971318 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -5,6 +5,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> +#include <glob.h> #include <algorithm> #include <fstream> @@ -1199,51 +1200,60 @@ void CConfigManager::handleSource(const std::string& command, const std::string& parseError = "source path " + rawpath + " bogus!"; return; } + std::unique_ptr<glob_t, void (*)(glob_t*)> glob_buf{new glob_t, [](glob_t* g) { globfree(g); }}; + memset(glob_buf.get(), 0, sizeof(glob_t)); - auto value = absolutePath(rawpath, configCurrentPath); - - if (!std::filesystem::exists(value)) { - Debug::log(ERR, "source= file doesnt exist"); - parseError = "source file " + value + " doesn't exist!"; + if (glob(rawpath.c_str(), GLOB_TILDE, nullptr, glob_buf.get()) != 0) { + Debug::log(ERR, "source= globbing error"); return; } - configPaths.push_back(value); + for (size_t i = 0; i < glob_buf->gl_pathc; i++) { + auto value = absolutePath(glob_buf->gl_pathv[i], configCurrentPath); - struct stat fileStat; - int err = stat(value.c_str(), &fileStat); - if (err != 0) { - Debug::log(WARN, "Error at ticking config at {}, error {}: {}", value, err, strerror(err)); - return; - } + if (!std::filesystem::exists(value)) { + Debug::log(ERR, "source= file doesnt exist"); + parseError = "source file " + value + " doesn't exist!"; + return; + } + configPaths.push_back(value); - configModifyTimes[value] = fileStat.st_mtime; + struct stat fileStat; + int err = stat(value.c_str(), &fileStat); + if (err != 0) { + Debug::log(WARN, "Error at ticking config at {}, error {}: {}", value, err, strerror(err)); + return; + } - std::ifstream ifs; - ifs.open(value); - std::string line = ""; - int linenum = 1; - if (ifs.is_open()) { - while (std::getline(ifs, line)) { - // Read line by line. - try { - configCurrentPath = value; - parseLine(line); - } catch (...) { - Debug::log(ERR, "Error reading line from config. Line:"); - Debug::log(NONE, "{}", line.c_str()); + configModifyTimes[value] = fileStat.st_mtime; - parseError += "Config error at line " + std::to_string(linenum) + " (" + configCurrentPath + "): Line parsing error."; - } + std::ifstream ifs; + ifs.open(value); - if (parseError != "" && parseError.find("Config error at line") != 0) { - parseError = "Config error at line " + std::to_string(linenum) + " (" + configCurrentPath + "): " + parseError; + std::string line = ""; + int linenum = 1; + if (ifs.is_open()) { + while (std::getline(ifs, line)) { + // Read line by line. + try { + configCurrentPath = value; + parseLine(line); + } catch (...) { + Debug::log(ERR, "Error reading line from config. Line:"); + Debug::log(NONE, "{}", line.c_str()); + + parseError += "Config error at line " + std::to_string(linenum) + " (" + configCurrentPath + "): Line parsing error."; + } + + if (parseError != "" && parseError.find("Config error at line") != 0) { + parseError = "Config error at line " + std::to_string(linenum) + " (" + configCurrentPath + "): " + parseError; + } + + ++linenum; } - ++linenum; + ifs.close(); } - - ifs.close(); } } |