mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-24 03:25:59 +01:00
hyprpm: move temp files to XDG_RUNTIME_DIR
avoid /tmp, it's cringe
This commit is contained in:
parent
745a82ce8a
commit
00d6261cc0
1 changed files with 28 additions and 16 deletions
|
@ -38,6 +38,18 @@ static std::string execAndGet(std::string cmd) {
|
||||||
return proc.stdOut();
|
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() {
|
SHyprlandVersion CPluginManager::getHyprlandVersion() {
|
||||||
static SHyprlandVersion ver;
|
static SHyprlandVersion ver;
|
||||||
static bool once = false;
|
static bool once = false;
|
||||||
|
@ -84,7 +96,7 @@ SHyprlandVersion CPluginManager::getHyprlandVersion() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPluginManager::createSafeDirectory(const std::string& path) {
|
bool CPluginManager::createSafeDirectory(const std::string& path) {
|
||||||
if (path.empty() || !path.starts_with("/tmp"))
|
if (path.empty() || !path.starts_with(getTempRoot()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (std::filesystem::exists(path))
|
if (std::filesystem::exists(path))
|
||||||
|
@ -142,17 +154,17 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string&
|
||||||
|
|
||||||
progress.print();
|
progress.print();
|
||||||
|
|
||||||
if (!std::filesystem::exists("/tmp/hyprpm")) {
|
if (!std::filesystem::exists(getTempRoot())) {
|
||||||
std::filesystem::create_directory("/tmp/hyprpm");
|
std::filesystem::create_directory(getTempRoot());
|
||||||
std::filesystem::permissions("/tmp/hyprpm", std::filesystem::perms::all, std::filesystem::perm_options::replace);
|
std::filesystem::permissions(getTempRoot(), std::filesystem::perms::owner_all, std::filesystem::perm_options::replace);
|
||||||
} else if (!std::filesystem::is_directory("/tmp/hyprpm")) {
|
} else if (!std::filesystem::is_directory(getTempRoot())) {
|
||||||
std::println(stderr, "\n{}", failureString("Could not prepare working dir for hyprpm"));
|
std::println(stderr, "\n{}", failureString("Could not prepare working dir for hyprpm"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string USERNAME = getpwuid(getuid())->pw_name;
|
const std::string USERNAME = getpwuid(getuid())->pw_name;
|
||||||
|
|
||||||
m_szWorkingPluginDirectory = "/tmp/hyprpm/" + USERNAME;
|
m_szWorkingPluginDirectory = getTempRoot() + USERNAME;
|
||||||
|
|
||||||
if (!createSafeDirectory(m_szWorkingPluginDirectory)) {
|
if (!createSafeDirectory(m_szWorkingPluginDirectory)) {
|
||||||
std::println(stderr, "\n{}", failureString("Could not prepare working dir for repo"));
|
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));
|
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")) {
|
if (!std::filesystem::exists(m_szWorkingPluginDirectory + "/.git")) {
|
||||||
std::println(stderr, "\n{}", failureString("Could not clone the plugin repository. shell returned:\n{}", ret));
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!std::filesystem::exists("/tmp/hyprpm")) {
|
if (!std::filesystem::exists(getTempRoot())) {
|
||||||
std::filesystem::create_directory("/tmp/hyprpm");
|
std::filesystem::create_directory(getTempRoot());
|
||||||
std::filesystem::permissions("/tmp/hyprpm", std::filesystem::perms::all, std::filesystem::perm_options::replace);
|
std::filesystem::permissions(getTempRoot(), std::filesystem::perms::owner_all, std::filesystem::perm_options::replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!force && headersValid() == HEADERS_OK) {
|
if (!force && headersValid() == HEADERS_OK) {
|
||||||
|
@ -430,7 +442,7 @@ bool CPluginManager::updateHeaders(bool force) {
|
||||||
progress.print();
|
progress.print();
|
||||||
|
|
||||||
const std::string USERNAME = getpwuid(getuid())->pw_name;
|
const std::string USERNAME = getpwuid(getuid())->pw_name;
|
||||||
const auto WORKINGDIR = "/tmp/hyprpm/hyprland-" + USERNAME;
|
const auto WORKINGDIR = getTempRoot() + "hyprland-" + USERNAME;
|
||||||
|
|
||||||
if (!createSafeDirectory(WORKINGDIR)) {
|
if (!createSafeDirectory(WORKINGDIR)) {
|
||||||
std::println("\n{}", failureString("Could not prepare working dir for hl"));
|
std::println("\n{}", failureString("Could not prepare working dir for hl"));
|
||||||
|
@ -448,12 +460,12 @@ bool CPluginManager::updateHeaders(bool force) {
|
||||||
if (m_bVerbose && bShallow)
|
if (m_bVerbose && bShallow)
|
||||||
progress.printMessageAbove(verboseString("will shallow since: {}", SHALLOW_DATE));
|
progress.printMessageAbove(verboseString("will shallow since: {}", SHALLOW_DATE));
|
||||||
|
|
||||||
std::string ret =
|
std::string ret = execAndGet(std::format("cd {} && git clone --recursive https://github.com/hyprwm/Hyprland hyprland-{}{}", getTempRoot(), USERNAME,
|
||||||
execAndGet("cd /tmp/hyprpm && git clone --recursive https://github.com/hyprwm/Hyprland hyprland-" + USERNAME + (bShallow ? " --shallow-since='" + SHALLOW_DATE + "'" : ""));
|
(bShallow ? " --shallow-since='" + SHALLOW_DATE + "'" : "")));
|
||||||
|
|
||||||
if (!std::filesystem::exists(WORKINGDIR)) {
|
if (!std::filesystem::exists(WORKINGDIR)) {
|
||||||
progress.printMessageAbove(failureString("Clone failed. Retrying without shallow."));
|
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")) {
|
if (!std::filesystem::exists(WORKINGDIR + "/.git")) {
|
||||||
|
@ -577,7 +589,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
|
||||||
progress.print();
|
progress.print();
|
||||||
|
|
||||||
const std::string USERNAME = getpwuid(getuid())->pw_name;
|
const std::string USERNAME = getpwuid(getuid())->pw_name;
|
||||||
m_szWorkingPluginDirectory = "/tmp/hyprpm/" + USERNAME;
|
m_szWorkingPluginDirectory = getTempRoot() + USERNAME;
|
||||||
|
|
||||||
for (auto const& repo : REPOS) {
|
for (auto const& repo : REPOS) {
|
||||||
bool update = forceUpdateAll;
|
bool update = forceUpdateAll;
|
||||||
|
@ -592,7 +604,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
|
||||||
|
|
||||||
progress.printMessageAbove(infoString("Cloning {}", repo.url));
|
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")) {
|
if (!std::filesystem::exists(m_szWorkingPluginDirectory + "/.git")) {
|
||||||
std::println("{}", failureString("could not clone repo: shell returned: {}", ret));
|
std::println("{}", failureString("could not clone repo: shell returned: {}", ret));
|
||||||
|
|
Loading…
Reference in a new issue