config: Minor --config improvements, fixes (#4034)

* Follow symlink, only file, absolute path for -c

* Create config file only for default paths

* Skip non-file source= glob results

* Check for absolute path on XDG_CONFIG_HOME

As per spec, all non-absolute paths should be ignored.
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
This commit is contained in:
dranull
2023-12-04 01:35:24 +00:00
committed by GitHub
parent e496b0f250
commit 9a9528d093
2 changed files with 28 additions and 21 deletions

View File

@@ -54,14 +54,17 @@ int main(int argc, char** argv) {
}
std::string next_arg = std::next(it)->c_str();
if (!std::filesystem::exists(next_arg)) {
std::cerr << "[ ERROR ] Config path '" << next_arg << "' doesn't exist!\n";
if (std::filesystem::is_symlink(next_arg))
next_arg = std::filesystem::read_symlink(next_arg);
if (!std::filesystem::is_regular_file(next_arg)) {
std::cerr << "[ ERROR ] Config file '" << next_arg << "' doesn't exist!\n";
help();
return 1;
}
configPath = next_arg;
configPath = std::filesystem::weakly_canonical(next_arg);
Debug::log(LOG, "User-specified config location: '{}'", configPath);
it++;