mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-25 06:49:49 +01:00
move data to DATA_HOME
This commit is contained in:
parent
02eae0a107
commit
a1420968a5
3 changed files with 22 additions and 41 deletions
|
@ -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())
|
||||
|
|
|
@ -8,6 +8,7 @@ struct SGlobalState {
|
|||
};
|
||||
|
||||
namespace DataState {
|
||||
std::string getDataStatePath();
|
||||
void ensureStateStoreExists();
|
||||
void addNewPluginRepo(const SPluginRepository& repo);
|
||||
void removePluginRepo(const std::string& urlOrName);
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue