From b4253550ac608e64e8a1ed215b69938461aa1004 Mon Sep 17 00:00:00 2001 From: hinto-janaiyo <hinto.janaiyo@protonmail.com> Date: Fri, 30 Dec 2022 09:39:03 -0500 Subject: [PATCH] Status Submenu: add Unix [750] perms for Gupax data folder --- src/constants.rs | 4 ++-- src/disk.rs | 28 ++++++++++++++++++++++++++-- src/status.rs | 10 ++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 79b82de..9ac72fa 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -179,8 +179,8 @@ pub const STATUS_SUBMENU_PAYOUT: &str = "The total amount of payouts received pub const STATUS_SUBMENU_XMR: &str = "The total of XMR mined via P2Pool across all time"; pub const STATUS_SUBMENU_LATEST: &str = "Sort the logs latest to oldest"; pub const STATUS_SUBMENU_OLDEST: &str = "Sort the logs oldest to latest"; -pub const STATUS_SUBMENU_BIGGEST: &str = "Sort the logs by biggest payouts first"; -pub const STATUS_SUBMENU_SMALLEST: &str = "Sort the logs by smallest payouts first"; +pub const STATUS_SUBMENU_BIGGEST: &str = "Sort the logs by the biggest payouts first"; +pub const STATUS_SUBMENU_SMALLEST: &str = "Sort the logs by the smallest payouts first"; // Gupax pub const GUPAX_UPDATE: &str = "Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically"; diff --git a/src/disk.rs b/src/disk.rs index ad001db..4a6eadd 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -51,6 +51,8 @@ use crate::{ P2poolRegex, }; use log::*; +#[cfg(target_family = "unix")] +use std::os::unix::fs::PermissionsExt; //---------------------------------------------------------------------------------------------------- Const // State file @@ -133,6 +135,26 @@ pub fn get_gupax_data_path() -> Result<PathBuf, TomlError> { } } +pub fn set_unix_750_perms(path: &PathBuf) -> Result<(), TomlError> { + #[cfg(target_os = "windows")] + return Ok(()); + #[cfg(target_family = "unix")] + match fs::set_permissions(path, fs::Permissions::from_mode(0o750)) { + Ok(_) => { info!("OS | Unix 750 permissions on path [{}] ... OK", path.display()); Ok(()) }, + Err(e) => { error!("OS | Unix 750 permissions on path [{}] ... FAIL ... {}", path.display(), e); Err(TomlError::Io(e)) }, + } +} + +pub fn set_unix_660_perms(path: &PathBuf) -> Result<(), TomlError> { + #[cfg(target_os = "windows")] + return Ok(()); + #[cfg(target_family = "unix")] + match fs::set_permissions(path, fs::Permissions::from_mode(0o660)) { + Ok(_) => { info!("OS | Unix 660 permissions on path [{}] ... OK", path.display()); Ok(()) }, + Err(e) => { error!("OS | Unix 660 permissions on path [{}] ... FAIL ... {}", path.display(), e); Err(TomlError::Io(e)) }, + } +} + pub fn get_gupax_p2pool_path(os_data_path: &PathBuf) -> PathBuf { let mut gupax_p2pool_dir = os_data_path.clone(); gupax_p2pool_dir.push(GUPAX_P2POOL_API_DIRECTORY); @@ -142,9 +164,10 @@ pub fn get_gupax_p2pool_path(os_data_path: &PathBuf) -> PathBuf { pub fn create_gupax_dir(path: &PathBuf) -> Result<(), TomlError> { // Create Gupax directory match fs::create_dir_all(path) { - Ok(_) => { info!("OS | Create data path ... OK"); Ok(()) }, - Err(e) => { error!("OS | Create data path ... FAIL ... {}", e); Err(TomlError::Io(e)) }, + Ok(_) => info!("OS | Create data path ... OK"), + Err(e) => { error!("OS | Create data path ... FAIL ... {}", e); return Err(TomlError::Io(e)) }, } + set_unix_750_perms(&path) } pub fn create_gupax_p2pool_dir(path: &PathBuf) -> Result<(), TomlError> { @@ -1156,6 +1179,7 @@ mod test { [status] submenu = "P2pool" + payout_view = "Oldest" monero_enabled = true manual_hash = false hashrate = 1241.23 diff --git a/src/status.rs b/src/status.rs index 7861b80..e238ab9 100644 --- a/src/status.rs +++ b/src/status.rs @@ -142,17 +142,19 @@ pub fn show(&mut self, sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolAp ui.add_sized([width, text], Label::new(RichText::new(format!("Total XMR: {}", api.xmr)).underline().color(LIGHT_GRAY))).on_hover_text(STATUS_SUBMENU_XMR); let width = width / 4.0; ui.separator(); - if ui.add_sized([width, text], SelectableLabel::new(self.payout_view == PayoutView::Latest, "Latest")).on_hover_text(STATUS_SUBMENU_LATEST).clicked() { self.payout_view = PayoutView::Latest; } + if ui.add_sized([width, text], SelectableLabel::new(self.payout_view == PayoutView::Latest, "Latest")).on_hover_text(STATUS_SUBMENU_LATEST).clicked() { + self.payout_view = PayoutView::Latest; + } ui.separator(); - if ui.add_sized([width, text], SelectableLabel::new(self.payout_view == PayoutView::Oldest, "Oldest")).on_hover_text(STATUS_SUBMENU_OLDEST).clicked() { self.payout_view = PayoutView::Oldest; } + if ui.add_sized([width, text], SelectableLabel::new(self.payout_view == PayoutView::Oldest, "Oldest")).on_hover_text(STATUS_SUBMENU_OLDEST).clicked() { + self.payout_view = PayoutView::Oldest; + } ui.separator(); if ui.add_sized([width, text], SelectableLabel::new(self.payout_view == PayoutView::Biggest, "Biggest")).on_hover_text(STATUS_SUBMENU_BIGGEST).clicked() { - api.update_payout_high(); self.payout_view = PayoutView::Biggest; } ui.separator(); if ui.add_sized([width, text], SelectableLabel::new(self.payout_view == PayoutView::Smallest, "Smallest")).on_hover_text(STATUS_SUBMENU_SMALLEST).clicked() { - api.update_payout_low(); self.payout_view = PayoutView::Smallest; } });