mirror of
https://github.com/hyprwm/hyprutils.git
synced 2024-11-17 06:05:59 +01:00
Path: add logs
This commit is contained in:
parent
0db21e96de
commit
4fb47606be
1 changed files with 15 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <hyprutils/path/Path.hpp>
|
#include <hyprutils/path/Path.hpp>
|
||||||
#include <hyprutils/string/VarList.hpp>
|
#include <hyprutils/string/VarList.hpp>
|
||||||
|
#include <hyprutils/debug/Log.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
using namespace Hyprutils;
|
using namespace Hyprutils;
|
||||||
|
@ -16,8 +17,10 @@ namespace Hyprutils::Path {
|
||||||
std::optional<std::string> getHome() {
|
std::optional<std::string> getHome() {
|
||||||
static const auto homeDir = getenv("HOME");
|
static const auto homeDir = getenv("HOME");
|
||||||
|
|
||||||
if (!homeDir || !std::filesystem::path(homeDir).is_absolute())
|
if (!homeDir || !std::filesystem::path(homeDir).is_absolute()) {
|
||||||
|
Debug::log(INFO, "'$HOME' is either not found or not an absolute path");
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
return std::string(homeDir).append("/.config");
|
return std::string(homeDir).append("/.config");
|
||||||
}
|
}
|
||||||
|
@ -25,8 +28,10 @@ namespace Hyprutils::Path {
|
||||||
std::optional<String::CVarList> getXdgConfigDirs() {
|
std::optional<String::CVarList> getXdgConfigDirs() {
|
||||||
static const auto xdgConfigDirs = getenv("XDG_CONFIG_DIRS");
|
static const auto xdgConfigDirs = getenv("XDG_CONFIG_DIRS");
|
||||||
|
|
||||||
if (!xdgConfigDirs)
|
if (!xdgConfigDirs) {
|
||||||
|
Debug::log(INFO, "'$XDG_CONFIG_DIRS' is not set");
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
static const auto xdgConfigDirsList = String::CVarList(xdgConfigDirs, 0, ':');
|
static const auto xdgConfigDirsList = String::CVarList(xdgConfigDirs, 0, ':');
|
||||||
|
|
||||||
|
@ -36,8 +41,10 @@ namespace Hyprutils::Path {
|
||||||
std::optional<std::string> getXdgConfigHome() {
|
std::optional<std::string> getXdgConfigHome() {
|
||||||
static const auto xdgConfigHome = getenv("XDG_CONFIG_HOME");
|
static const auto xdgConfigHome = getenv("XDG_CONFIG_HOME");
|
||||||
|
|
||||||
if (!xdgConfigHome || !std::filesystem::path(xdgConfigHome).is_absolute())
|
if (!xdgConfigHome || !std::filesystem::path(xdgConfigHome).is_absolute()) {
|
||||||
|
Debug::log(INFO, "'$XDG_CONFIG_HOME' is either not found or not an absolute path");
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
return xdgConfigHome;
|
return xdgConfigHome;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +57,7 @@ namespace Hyprutils::Path {
|
||||||
xdgConfigHomeExists = true;
|
xdgConfigHomeExists = true;
|
||||||
if (checkConfigExists(xdgConfigHome.value(), programName))
|
if (checkConfigExists(xdgConfigHome.value(), programName))
|
||||||
return std::make_pair(fullConfigPath(xdgConfigHome.value(), programName), xdgConfigHome);
|
return std::make_pair(fullConfigPath(xdgConfigHome.value(), programName), xdgConfigHome);
|
||||||
|
Debug::log(INFO, "No config file could be found in {}/{}", xdgConfigHome.value(), programName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool homeExists = false;
|
bool homeExists = false;
|
||||||
|
@ -58,6 +66,7 @@ namespace Hyprutils::Path {
|
||||||
homeExists = true;
|
homeExists = true;
|
||||||
if (checkConfigExists(home.value(), programName))
|
if (checkConfigExists(home.value(), programName))
|
||||||
return std::make_pair(fullConfigPath(home.value(), programName), home);
|
return std::make_pair(fullConfigPath(home.value(), programName), home);
|
||||||
|
Debug::log(INFO, "No config file could be found in {}/{}", home.value(), programName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const auto xdgConfigDirs = getXdgConfigDirs();
|
static const auto xdgConfigDirs = getXdgConfigDirs();
|
||||||
|
@ -65,17 +74,20 @@ namespace Hyprutils::Path {
|
||||||
for (auto dir : xdgConfigDirs.value()) {
|
for (auto dir : xdgConfigDirs.value()) {
|
||||||
if (checkConfigExists(dir, programName))
|
if (checkConfigExists(dir, programName))
|
||||||
return std::make_pair(fullConfigPath(dir, programName), std::nullopt);
|
return std::make_pair(fullConfigPath(dir, programName), std::nullopt);
|
||||||
|
Debug::log(INFO, "No config file could be found in {}/{}", dir, programName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkConfigExists("/etc/xdg", programName))
|
if (checkConfigExists("/etc/xdg", programName))
|
||||||
return std::make_pair(fullConfigPath("/etc/xdg", programName), std::nullopt);
|
return std::make_pair(fullConfigPath("/etc/xdg", programName), std::nullopt);
|
||||||
|
Debug::log(INFO, "No config file could be found in /etc/xdg/{}", programName);
|
||||||
|
|
||||||
if (xdgConfigHomeExists)
|
if (xdgConfigHomeExists)
|
||||||
return std::make_pair(std::nullopt, xdgConfigHome);
|
return std::make_pair(std::nullopt, xdgConfigHome);
|
||||||
else if (homeExists)
|
else if (homeExists)
|
||||||
return std::make_pair(std::nullopt, home);
|
return std::make_pair(std::nullopt, home);
|
||||||
|
|
||||||
|
Debug::log(ERR, "No config file could be found. Check previous logs for clues");
|
||||||
return std::make_pair(std::nullopt, std::nullopt);
|
return std::make_pair(std::nullopt, std::nullopt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue