mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-25 19:09:48 +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 <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
void DataState::ensureStateStoreExists() {
|
std::string DataState::getDataStatePath() {
|
||||||
const auto HOME = getenv("HOME");
|
const auto HOME = getenv("HOME");
|
||||||
if (!HOME) {
|
if (!HOME) {
|
||||||
std::cerr << "DataState: no $HOME\n";
|
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))
|
if (!std::filesystem::exists(PATH))
|
||||||
std::filesystem::create_directories(PATH);
|
std::filesystem::create_directories(PATH);
|
||||||
|
@ -19,12 +29,7 @@ void DataState::ensureStateStoreExists() {
|
||||||
void DataState::addNewPluginRepo(const SPluginRepository& repo) {
|
void DataState::addNewPluginRepo(const SPluginRepository& repo) {
|
||||||
ensureStateStoreExists();
|
ensureStateStoreExists();
|
||||||
|
|
||||||
const auto HOME = getenv("HOME");
|
const auto PATH = getDataStatePath() + "/" + repo.name;
|
||||||
if (!HOME) {
|
|
||||||
std::cerr << "DataState: no $HOME\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto PATH = std::string(HOME) + "/.hyprpm/" + repo.name;
|
|
||||||
|
|
||||||
std::filesystem::create_directories(PATH);
|
std::filesystem::create_directories(PATH);
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -54,12 +59,7 @@ void DataState::addNewPluginRepo(const SPluginRepository& repo) {
|
||||||
bool DataState::pluginRepoExists(const std::string& urlOrName) {
|
bool DataState::pluginRepoExists(const std::string& urlOrName) {
|
||||||
ensureStateStoreExists();
|
ensureStateStoreExists();
|
||||||
|
|
||||||
const auto HOME = getenv("HOME");
|
const auto PATH = getDataStatePath();
|
||||||
if (!HOME) {
|
|
||||||
std::cerr << "DataState: no $HOME\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const auto PATH = std::string(HOME) + "/.hyprpm/";
|
|
||||||
|
|
||||||
for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
|
for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
|
||||||
if (!entry.is_directory())
|
if (!entry.is_directory())
|
||||||
|
@ -80,12 +80,7 @@ bool DataState::pluginRepoExists(const std::string& urlOrName) {
|
||||||
void DataState::removePluginRepo(const std::string& urlOrName) {
|
void DataState::removePluginRepo(const std::string& urlOrName) {
|
||||||
ensureStateStoreExists();
|
ensureStateStoreExists();
|
||||||
|
|
||||||
const auto HOME = getenv("HOME");
|
const auto PATH = getDataStatePath();
|
||||||
if (!HOME) {
|
|
||||||
std::cerr << "DataState: no $HOME\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto PATH = std::string(HOME) + "/.hyprpm/";
|
|
||||||
|
|
||||||
for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
|
for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
|
||||||
if (!entry.is_directory())
|
if (!entry.is_directory())
|
||||||
|
@ -106,12 +101,7 @@ void DataState::removePluginRepo(const std::string& urlOrName) {
|
||||||
void DataState::updateGlobalState(const SGlobalState& state) {
|
void DataState::updateGlobalState(const SGlobalState& state) {
|
||||||
ensureStateStoreExists();
|
ensureStateStoreExists();
|
||||||
|
|
||||||
const auto HOME = getenv("HOME");
|
const auto PATH = getDataStatePath();
|
||||||
if (!HOME) {
|
|
||||||
std::cerr << "DataState: no $HOME\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto PATH = std::string(HOME) + "/.hyprpm/";
|
|
||||||
|
|
||||||
std::filesystem::create_directories(PATH);
|
std::filesystem::create_directories(PATH);
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -130,12 +120,7 @@ void DataState::updateGlobalState(const SGlobalState& state) {
|
||||||
std::vector<SPluginRepository> DataState::getAllRepositories() {
|
std::vector<SPluginRepository> DataState::getAllRepositories() {
|
||||||
ensureStateStoreExists();
|
ensureStateStoreExists();
|
||||||
|
|
||||||
const auto HOME = getenv("HOME");
|
const auto PATH = getDataStatePath();
|
||||||
if (!HOME) {
|
|
||||||
std::cerr << "DataState: no $HOME\n";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
const auto PATH = std::string(HOME) + "/.hyprpm/";
|
|
||||||
|
|
||||||
std::vector<SPluginRepository> repos;
|
std::vector<SPluginRepository> repos;
|
||||||
|
|
||||||
|
@ -173,12 +158,7 @@ std::vector<SPluginRepository> DataState::getAllRepositories() {
|
||||||
bool DataState::setPluginEnabled(const std::string& name, bool enabled) {
|
bool DataState::setPluginEnabled(const std::string& name, bool enabled) {
|
||||||
ensureStateStoreExists();
|
ensureStateStoreExists();
|
||||||
|
|
||||||
const auto HOME = getenv("HOME");
|
const auto PATH = getDataStatePath();
|
||||||
if (!HOME) {
|
|
||||||
std::cerr << "DataState: no $HOME\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const auto PATH = std::string(HOME) + "/.hyprpm/";
|
|
||||||
|
|
||||||
for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
|
for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
|
||||||
if (!entry.is_directory())
|
if (!entry.is_directory())
|
||||||
|
|
|
@ -8,6 +8,7 @@ struct SGlobalState {
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace DataState {
|
namespace DataState {
|
||||||
|
std::string getDataStatePath();
|
||||||
void ensureStateStoreExists();
|
void ensureStateStoreExists();
|
||||||
void addNewPluginRepo(const SPluginRepository& repo);
|
void addNewPluginRepo(const SPluginRepository& repo);
|
||||||
void removePluginRepo(const std::string& urlOrName);
|
void removePluginRepo(const std::string& urlOrName);
|
||||||
|
|
|
@ -157,7 +157,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) {
|
||||||
progress.m_szCurrentMessage = "Installing repository";
|
progress.m_szCurrentMessage = "Installing repository";
|
||||||
progress.print();
|
progress.print();
|
||||||
|
|
||||||
// add repo toml to ~/.hyprpm
|
// add repo toml to DataState
|
||||||
SPluginRepository repo;
|
SPluginRepository repo;
|
||||||
std::string repohash = execAndGet("cd /tmp/hyprpm/new/ && git rev-parse HEAD");
|
std::string repohash = execAndGet("cd /tmp/hyprpm/new/ && git rev-parse HEAD");
|
||||||
if (repohash.length() > 0)
|
if (repohash.length() > 0)
|
||||||
|
@ -491,7 +491,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
|
||||||
if (failed)
|
if (failed)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// add repo toml to ~/.hyprpm
|
// add repo toml to DataState
|
||||||
SPluginRepository newrepo = repo;
|
SPluginRepository newrepo = repo;
|
||||||
newrepo.plugins.clear();
|
newrepo.plugins.clear();
|
||||||
std::string repohash = execAndGet(
|
std::string repohash = execAndGet(
|
||||||
|
|
Loading…
Reference in a new issue