diff options
author | Vaxry <[email protected]> | 2023-12-06 17:38:39 +0000 |
---|---|---|
committer | Vaxry <[email protected]> | 2023-12-06 23:31:03 +0000 |
commit | a1420968a539708fd06c10d84c56fa26e22f2204 (patch) | |
tree | 34b916494794d0d4ab097309427e60034d711e57 | |
parent | 02eae0a10769b1dc2f57a3545b9d82aa960ac0b8 (diff) | |
download | Hyprland-a1420968a539708fd06c10d84c56fa26e22f2204.tar.gz Hyprland-a1420968a539708fd06c10d84c56fa26e22f2204.zip |
move data to DATA_HOME
-rw-r--r-- | hyprpm/src/core/DataState.cpp | 58 | ||||
-rw-r--r-- | hyprpm/src/core/DataState.hpp | 1 | ||||
-rw-r--r-- | hyprpm/src/core/PluginManager.cpp | 4 |
3 files changed, 22 insertions, 41 deletions
diff --git a/hyprpm/src/core/DataState.cpp b/hyprpm/src/core/DataState.cpp index 562dc880..81aebeb2 100644 --- a/hyprpm/src/core/DataState.cpp +++ b/hyprpm/src/core/DataState.cpp @@ -4,13 +4,23 @@ #include <filesystem> #include <fstream> -void DataState::ensureStateStoreExists() { +std::string DataState::getDataStatePath() { const auto HOME = getenv("HOME"); if (!HOME) { std::cerr << "DataState: no $HOME\n"; - return; + throw std::runtime_error("no $HOME"); + return ""; } - const auto PATH = std::string(HOME) + "/.hyprpm/"; + + const auto XDG_DATA_HOME = getenv("XDG_DATA_HOME"); + + if (XDG_DATA_HOME) + return std::string{XDG_DATA_HOME} + "/hyprpm"; + return std::string{HOME} + "/.local/share/hyprpm"; +} + +void DataState::ensureStateStoreExists() { + const auto PATH = getDataStatePath(); if (!std::filesystem::exists(PATH)) std::filesystem::create_directories(PATH); @@ -19,12 +29,7 @@ void DataState::ensureStateStoreExists() { void DataState::addNewPluginRepo(const SPluginRepository& repo) { ensureStateStoreExists(); - const auto HOME = getenv("HOME"); - if (!HOME) { - std::cerr << "DataState: no $HOME\n"; - return; - } - const auto PATH = std::string(HOME) + "/.hyprpm/" + repo.name; + const auto PATH = getDataStatePath() + "/" + repo.name; std::filesystem::create_directories(PATH); // clang-format off @@ -54,12 +59,7 @@ void DataState::addNewPluginRepo(const SPluginRepository& repo) { bool DataState::pluginRepoExists(const std::string& urlOrName) { ensureStateStoreExists(); - const auto HOME = getenv("HOME"); - if (!HOME) { - std::cerr << "DataState: no $HOME\n"; - return false; - } - const auto PATH = std::string(HOME) + "/.hyprpm/"; + const auto PATH = getDataStatePath(); for (const auto& entry : std::filesystem::directory_iterator(PATH)) { if (!entry.is_directory()) @@ -80,12 +80,7 @@ bool DataState::pluginRepoExists(const std::string& urlOrName) { void DataState::removePluginRepo(const std::string& urlOrName) { ensureStateStoreExists(); - const auto HOME = getenv("HOME"); - if (!HOME) { - std::cerr << "DataState: no $HOME\n"; - return; - } - const auto PATH = std::string(HOME) + "/.hyprpm/"; + const auto PATH = getDataStatePath(); for (const auto& entry : std::filesystem::directory_iterator(PATH)) { if (!entry.is_directory()) @@ -106,12 +101,7 @@ void DataState::removePluginRepo(const std::string& urlOrName) { void DataState::updateGlobalState(const SGlobalState& state) { ensureStateStoreExists(); - const auto HOME = getenv("HOME"); - if (!HOME) { - std::cerr << "DataState: no $HOME\n"; - return; - } - const auto PATH = std::string(HOME) + "/.hyprpm/"; + const auto PATH = getDataStatePath(); std::filesystem::create_directories(PATH); // clang-format off @@ -130,12 +120,7 @@ void DataState::updateGlobalState(const SGlobalState& state) { std::vector<SPluginRepository> DataState::getAllRepositories() { ensureStateStoreExists(); - const auto HOME = getenv("HOME"); - if (!HOME) { - std::cerr << "DataState: no $HOME\n"; - return {}; - } - const auto PATH = std::string(HOME) + "/.hyprpm/"; + const auto PATH = getDataStatePath(); std::vector<SPluginRepository> repos; @@ -173,12 +158,7 @@ std::vector<SPluginRepository> DataState::getAllRepositories() { bool DataState::setPluginEnabled(const std::string& name, bool enabled) { ensureStateStoreExists(); - const auto HOME = getenv("HOME"); - if (!HOME) { - std::cerr << "DataState: no $HOME\n"; - return false; - } - const auto PATH = std::string(HOME) + "/.hyprpm/"; + const auto PATH = getDataStatePath(); for (const auto& entry : std::filesystem::directory_iterator(PATH)) { if (!entry.is_directory()) diff --git a/hyprpm/src/core/DataState.hpp b/hyprpm/src/core/DataState.hpp index f789c530..cd609dba 100644 --- a/hyprpm/src/core/DataState.hpp +++ b/hyprpm/src/core/DataState.hpp @@ -8,6 +8,7 @@ struct SGlobalState { }; namespace DataState { + std::string getDataStatePath(); void ensureStateStoreExists(); void addNewPluginRepo(const SPluginRepository& repo); void removePluginRepo(const std::string& urlOrName); diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 4cba72bd..5f379587 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -157,7 +157,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) { progress.m_szCurrentMessage = "Installing repository"; progress.print(); - // add repo toml to ~/.hyprpm + // add repo toml to DataState SPluginRepository repo; std::string repohash = execAndGet("cd /tmp/hyprpm/new/ && git rev-parse HEAD"); if (repohash.length() > 0) @@ -491,7 +491,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { if (failed) continue; - // add repo toml to ~/.hyprpm + // add repo toml to DataState SPluginRepository newrepo = repo; newrepo.plugins.clear(); std::string repohash = execAndGet( |