diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index db315193..fb3065b4 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -38,6 +38,18 @@ static std::string execAndGet(std::string cmd) { return proc.stdOut(); } +static std::string getTempRoot() { + static auto ENV = getenv("XDG_RUNTIME_DIR"); + if (!ENV) { + std::cerr << "\nERROR: XDG_RUNTIME_DIR not set!\n"; + exit(1); + } + + const auto STR = ENV + std::string{"/hyprpm/"}; + + return STR; +} + SHyprlandVersion CPluginManager::getHyprlandVersion() { static SHyprlandVersion ver; static bool once = false; @@ -84,7 +96,7 @@ SHyprlandVersion CPluginManager::getHyprlandVersion() { } bool CPluginManager::createSafeDirectory(const std::string& path) { - if (path.empty() || !path.starts_with("/tmp")) + if (path.empty() || !path.starts_with(getTempRoot())) return false; if (std::filesystem::exists(path)) @@ -142,17 +154,17 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& progress.print(); - if (!std::filesystem::exists("/tmp/hyprpm")) { - std::filesystem::create_directory("/tmp/hyprpm"); - std::filesystem::permissions("/tmp/hyprpm", std::filesystem::perms::all, std::filesystem::perm_options::replace); - } else if (!std::filesystem::is_directory("/tmp/hyprpm")) { + if (!std::filesystem::exists(getTempRoot())) { + std::filesystem::create_directory(getTempRoot()); + std::filesystem::permissions(getTempRoot(), std::filesystem::perms::owner_all, std::filesystem::perm_options::replace); + } else if (!std::filesystem::is_directory(getTempRoot())) { std::println(stderr, "\n{}", failureString("Could not prepare working dir for hyprpm")); return false; } const std::string USERNAME = getpwuid(getuid())->pw_name; - m_szWorkingPluginDirectory = "/tmp/hyprpm/" + USERNAME; + m_szWorkingPluginDirectory = getTempRoot() + USERNAME; if (!createSafeDirectory(m_szWorkingPluginDirectory)) { std::println(stderr, "\n{}", failureString("Could not prepare working dir for repo")); @@ -161,7 +173,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& progress.printMessageAbove(infoString("Cloning {}", url)); - std::string ret = execAndGet("cd /tmp/hyprpm && git clone --recursive " + url + " " + USERNAME); + std::string ret = execAndGet(std::format("cd {} && git clone --recursive {} {}", getTempRoot(), url, USERNAME)); if (!std::filesystem::exists(m_szWorkingPluginDirectory + "/.git")) { std::println(stderr, "\n{}", failureString("Could not clone the plugin repository. shell returned:\n{}", ret)); @@ -413,9 +425,9 @@ bool CPluginManager::updateHeaders(bool force) { return false; } - if (!std::filesystem::exists("/tmp/hyprpm")) { - std::filesystem::create_directory("/tmp/hyprpm"); - std::filesystem::permissions("/tmp/hyprpm", std::filesystem::perms::all, std::filesystem::perm_options::replace); + if (!std::filesystem::exists(getTempRoot())) { + std::filesystem::create_directory(getTempRoot()); + std::filesystem::permissions(getTempRoot(), std::filesystem::perms::owner_all, std::filesystem::perm_options::replace); } if (!force && headersValid() == HEADERS_OK) { @@ -430,7 +442,7 @@ bool CPluginManager::updateHeaders(bool force) { progress.print(); const std::string USERNAME = getpwuid(getuid())->pw_name; - const auto WORKINGDIR = "/tmp/hyprpm/hyprland-" + USERNAME; + const auto WORKINGDIR = getTempRoot() + "hyprland-" + USERNAME; if (!createSafeDirectory(WORKINGDIR)) { std::println("\n{}", failureString("Could not prepare working dir for hl")); @@ -448,12 +460,12 @@ bool CPluginManager::updateHeaders(bool force) { if (m_bVerbose && bShallow) progress.printMessageAbove(verboseString("will shallow since: {}", SHALLOW_DATE)); - std::string ret = - execAndGet("cd /tmp/hyprpm && git clone --recursive https://github.com/hyprwm/Hyprland hyprland-" + USERNAME + (bShallow ? " --shallow-since='" + SHALLOW_DATE + "'" : "")); + std::string ret = execAndGet(std::format("cd {} && git clone --recursive https://github.com/hyprwm/Hyprland hyprland-{}{}", getTempRoot(), USERNAME, + (bShallow ? " --shallow-since='" + SHALLOW_DATE + "'" : ""))); if (!std::filesystem::exists(WORKINGDIR)) { progress.printMessageAbove(failureString("Clone failed. Retrying without shallow.")); - ret = execAndGet("cd /tmp/hyprpm && git clone --recursive https://github.com/hyprwm/hyprland hyprland-" + USERNAME); + ret = execAndGet(std::format("cd {} && git clone --recursive https://github.com/hyprwm/hyprland hyprland-{}", getTempRoot(), USERNAME)); } if (!std::filesystem::exists(WORKINGDIR + "/.git")) { @@ -577,7 +589,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { progress.print(); const std::string USERNAME = getpwuid(getuid())->pw_name; - m_szWorkingPluginDirectory = "/tmp/hyprpm/" + USERNAME; + m_szWorkingPluginDirectory = getTempRoot() + USERNAME; for (auto const& repo : REPOS) { bool update = forceUpdateAll; @@ -592,7 +604,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { progress.printMessageAbove(infoString("Cloning {}", repo.url)); - std::string ret = execAndGet("cd /tmp/hyprpm && git clone --recursive " + repo.url + " " + USERNAME); + std::string ret = execAndGet(std::format("cd {} && git clone --recursive {} {}", getTempRoot(), repo.url, USERNAME)); if (!std::filesystem::exists(m_szWorkingPluginDirectory + "/.git")) { std::println("{}", failureString("could not clone repo: shell returned: {}", ret));