From 360fb143851e95bbeb8237b9673fa33e1bffc1a3 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 10 Sep 2024 19:59:07 +0300 Subject: [PATCH] Path: simplify --- src/path/Path.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/path/Path.cpp b/src/path/Path.cpp index ea9a94f..06c8aba 100644 --- a/src/path/Path.cpp +++ b/src/path/Path.cpp @@ -51,36 +51,42 @@ namespace Hyprutils::Path { using T = std::optional; std::pair findConfig(std::string programName) { + std::string configPath; + bool xdgConfigHomeExists = false; static const auto xdgConfigHome = getXdgConfigHome(); if (xdgConfigHome.has_value()) { xdgConfigHomeExists = true; - if (checkConfigExists(xdgConfigHome.value(), programName)) - return std::make_pair(fullConfigPath(xdgConfigHome.value(), programName), xdgConfigHome); - Debug::log(INFO, "No config file could be found in {}/{}", xdgConfigHome.value(), programName); + configPath = fullConfigPath(xdgConfigHome.value(), programName); + if (std::filesystem::exists(configPath)) + return std::make_pair(configPath, xdgConfigHome); + Debug::log(INFO, "No config file {}", configPath); } bool homeExists = false; static const auto home = getHome(); if (home.has_value()) { homeExists = true; - if (checkConfigExists(home.value(), programName)) - return std::make_pair(fullConfigPath(home.value(), programName), home); - Debug::log(INFO, "No config file could be found in {}/{}", home.value(), programName); + configPath = fullConfigPath(home.value(), programName); + if (std::filesystem::exists(configPath)) + return std::make_pair(configPath, home); + Debug::log(INFO, "No config file {}", configPath); } static const auto xdgConfigDirs = getXdgConfigDirs(); if (xdgConfigDirs.has_value()) { for (auto dir : xdgConfigDirs.value()) { - if (checkConfigExists(dir, programName)) - return std::make_pair(fullConfigPath(dir, programName), std::nullopt); - Debug::log(INFO, "No config file could be found in {}/{}", dir, programName); + configPath = fullConfigPath(dir, programName); + if (std::filesystem::exists(configPath)) + return std::make_pair(configPath, std::nullopt); + Debug::log(INFO, "No config file {}", configPath); } } - if (checkConfigExists("/etc/xdg", programName)) - return std::make_pair(fullConfigPath("/etc/xdg", programName), std::nullopt); - Debug::log(INFO, "No config file could be found in /etc/xdg/{}", programName); + configPath = fullConfigPath("/etc/xdg", programName); + if (std::filesystem::exists(configPath)) + return std::make_pair(configPath, std::nullopt); + Debug::log(INFO, "No config file {}", configPath); if (xdgConfigHomeExists) return std::make_pair(std::nullopt, xdgConfigHome);