Path: use vec instead of set

This commit is contained in:
Mihai Fufezan 2024-09-10 22:28:12 +03:00
parent 01f69fab15
commit 5486995a00
Signed by: fufexan
SSH Key Fingerprint: SHA256:SdnKmEpJrDu1+2UO1QpB/Eg4HKcdDi6n+xSRqFNJVpg
1 changed files with 11 additions and 6 deletions

View File

@ -2,7 +2,7 @@
#include <hyprutils/string/VarList.hpp> #include <hyprutils/string/VarList.hpp>
#include <hyprutils/debug/Log.hpp> #include <hyprutils/debug/Log.hpp>
#include <filesystem> #include <filesystem>
#include <set> #include <vector>
using namespace Hyprutils; using namespace Hyprutils;
@ -11,6 +11,11 @@ namespace Hyprutils::Path {
return basePath + "/hypr/" + programName + ".conf"; return basePath + "/hypr/" + programName + ".conf";
} }
void push_if_new(std::vector<std::string> vec, std::string str) {
if (std::find(vec.begin(), vec.end(), str) == vec.end())
vec.push_back(str);
}
std::optional<std::string> getHome() { std::optional<std::string> getHome() {
static const auto homeDir = getenv("HOME"); static const auto homeDir = getenv("HOME");
@ -49,23 +54,23 @@ namespace Hyprutils::Path {
using T = std::optional<std::string>; using T = std::optional<std::string>;
std::pair<T, T> findConfig(std::string programName) { std::pair<T, T> findConfig(std::string programName) {
std::string configPath; std::string configPath;
std::set<std::string> paths; std::vector<std::string> paths;
static const auto xdgConfigHome = getXdgConfigHome(); static const auto xdgConfigHome = getXdgConfigHome();
if (xdgConfigHome.has_value()) if (xdgConfigHome.has_value())
paths.insert(xdgConfigHome.value()); push_if_new(paths, xdgConfigHome.value());
static const auto home = getHome(); static const auto home = getHome();
if (home.has_value()) if (home.has_value())
paths.insert(home.value()); push_if_new(paths, home.value());
static const auto xdgConfigDirs = getXdgConfigDirs(); static const auto xdgConfigDirs = getXdgConfigDirs();
if (xdgConfigDirs.has_value()) { if (xdgConfigDirs.has_value()) {
for (auto dir : xdgConfigDirs.value()) for (auto dir : xdgConfigDirs.value())
paths.insert(dir); push_if_new(paths, dir);
} }
paths.insert("/etc/xdg"); push_if_new(paths, "/etc/xdg");
for (auto path : paths) { for (auto path : paths) {
configPath = fullConfigPath(path, programName); configPath = fullConfigPath(path, programName);