Status Submenu: add Unix [750] perms for Gupax data folder

This commit is contained in:
hinto-janaiyo 2022-12-30 09:39:03 -05:00
parent 553081d2aa
commit 08cda22e68
No known key found for this signature in database
GPG key ID: B1C5A64B80691E45
3 changed files with 34 additions and 8 deletions

View file

@ -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_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_LATEST: &str = "Sort the logs latest to oldest";
pub const STATUS_SUBMENU_OLDEST: &str = "Sort the logs oldest to latest"; 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_BIGGEST: &str = "Sort the logs by the biggest payouts first";
pub const STATUS_SUBMENU_SMALLEST: &str = "Sort the logs by smallest payouts first"; pub const STATUS_SUBMENU_SMALLEST: &str = "Sort the logs by the smallest payouts first";
// Gupax // Gupax
pub const GUPAX_UPDATE: &str = "Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically"; pub const GUPAX_UPDATE: &str = "Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically";

View file

@ -51,6 +51,8 @@ use crate::{
P2poolRegex, P2poolRegex,
}; };
use log::*; use log::*;
#[cfg(target_family = "unix")]
use std::os::unix::fs::PermissionsExt;
//---------------------------------------------------------------------------------------------------- Const //---------------------------------------------------------------------------------------------------- Const
// State file // 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 { pub fn get_gupax_p2pool_path(os_data_path: &PathBuf) -> PathBuf {
let mut gupax_p2pool_dir = os_data_path.clone(); let mut gupax_p2pool_dir = os_data_path.clone();
gupax_p2pool_dir.push(GUPAX_P2POOL_API_DIRECTORY); 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> { pub fn create_gupax_dir(path: &PathBuf) -> Result<(), TomlError> {
// Create Gupax directory // Create Gupax directory
match fs::create_dir_all(path) { match fs::create_dir_all(path) {
Ok(_) => { info!("OS | Create data path ... OK"); Ok(()) }, Ok(_) => info!("OS | Create data path ... OK"),
Err(e) => { error!("OS | Create data path ... FAIL ... {}", e); Err(TomlError::Io(e)) }, 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> { pub fn create_gupax_p2pool_dir(path: &PathBuf) -> Result<(), TomlError> {
@ -1156,6 +1179,7 @@ mod test {
[status] [status]
submenu = "P2pool" submenu = "P2pool"
payout_view = "Oldest"
monero_enabled = true monero_enabled = true
manual_hash = false manual_hash = false
hashrate = 1241.23 hashrate = 1241.23

View file

@ -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); 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; let width = width / 4.0;
ui.separator(); 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(); 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(); ui.separator();
if ui.add_sized([width, text], SelectableLabel::new(self.payout_view == PayoutView::Biggest, "Biggest")).on_hover_text(STATUS_SUBMENU_BIGGEST).clicked() { 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; self.payout_view = PayoutView::Biggest;
} }
ui.separator(); ui.separator();
if ui.add_sized([width, text], SelectableLabel::new(self.payout_view == PayoutView::Smallest, "Smallest")).on_hover_text(STATUS_SUBMENU_SMALLEST).clicked() { 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; self.payout_view = PayoutView::Smallest;
} }
}); });