From 9a9528d09375e6017088af354799ac381b939c1f Mon Sep 17 00:00:00 2001 From: dranull <150595692+dranull@users.noreply.github.com> Date: Mon, 4 Dec 2023 01:35:24 +0000 Subject: 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 --- src/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 27a768ba..0f68c3b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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++; -- cgit v1.2.3