config: add wildcard handling in source= (#3276)

This commit is contained in:
memchr 2023-09-12 11:54:05 +00:00 committed by GitHub
parent 9192b20b96
commit 5cc53c14d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <glob.h>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
@ -1199,15 +1200,22 @@ void CConfigManager::handleSource(const std::string& command, const std::string&
parseError = "source path " + rawpath + " bogus!"; parseError = "source path " + rawpath + " bogus!";
return; 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 (glob(rawpath.c_str(), GLOB_TILDE, nullptr, glob_buf.get()) != 0) {
Debug::log(ERR, "source= globbing error");
return;
}
for (size_t i = 0; i < glob_buf->gl_pathc; i++) {
auto value = absolutePath(glob_buf->gl_pathv[i], configCurrentPath);
if (!std::filesystem::exists(value)) { if (!std::filesystem::exists(value)) {
Debug::log(ERR, "source= file doesnt exist"); Debug::log(ERR, "source= file doesnt exist");
parseError = "source file " + value + " doesn't exist!"; parseError = "source file " + value + " doesn't exist!";
return; return;
} }
configPaths.push_back(value); configPaths.push_back(value);
struct stat fileStat; struct stat fileStat;
@ -1221,6 +1229,7 @@ void CConfigManager::handleSource(const std::string& command, const std::string&
std::ifstream ifs; std::ifstream ifs;
ifs.open(value); ifs.open(value);
std::string line = ""; std::string line = "";
int linenum = 1; int linenum = 1;
if (ifs.is_open()) { if (ifs.is_open()) {
@ -1245,6 +1254,7 @@ void CConfigManager::handleSource(const std::string& command, const std::string&
ifs.close(); ifs.close();
} }
}
} }
void CConfigManager::handleBindWS(const std::string& command, const std::string& value) { void CConfigManager::handleBindWS(const std::string& command, const std::string& value) {