Skip to content

Commit

Permalink
fix: clippy non auto fixable warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrix126 committed Feb 27, 2024
1 parent 2c7a117 commit ffceb4b
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 72 deletions.
23 changes: 11 additions & 12 deletions src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use log::*;
use serde::{Deserialize, Serialize};
#[cfg(target_family = "unix")]
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use std::{
fmt::Display,
fmt::Write,
Expand Down Expand Up @@ -179,8 +180,8 @@ pub fn set_unix_660_perms(path: &PathBuf) -> Result<(), TomlError> {
}
}

pub fn get_gupax_p2pool_path(os_data_path: &PathBuf) -> PathBuf {
let mut gupax_p2pool_dir = os_data_path.clone();
pub fn get_gupax_p2pool_path(os_data_path: &Path) -> PathBuf {
let mut gupax_p2pool_dir = os_data_path.to_path_buf();
gupax_p2pool_dir.push(GUPAX_P2POOL_API_DIRECTORY);
gupax_p2pool_dir
}
Expand Down Expand Up @@ -728,10 +729,10 @@ impl GupaxP2poolApi {
}
}

pub fn fill_paths(&mut self, gupax_p2pool_dir: &PathBuf) {
let mut path_log = gupax_p2pool_dir.clone();
let mut path_payout = gupax_p2pool_dir.clone();
let mut path_xmr = gupax_p2pool_dir.clone();
pub fn fill_paths(&mut self, gupax_p2pool_dir: &Path) {
let mut path_log = gupax_p2pool_dir.to_path_buf();
let mut path_payout = gupax_p2pool_dir.to_path_buf();
let mut path_xmr = gupax_p2pool_dir.to_path_buf();
path_log.push(GUPAX_P2POOL_API_LOG);
path_payout.push(GUPAX_P2POOL_API_PAYOUT);
path_xmr.push(GUPAX_P2POOL_API_XMR);
Expand All @@ -743,10 +744,10 @@ impl GupaxP2poolApi {
};
}

pub fn create_all_files(gupax_p2pool_dir: &PathBuf) -> Result<(), TomlError> {
pub fn create_all_files(gupax_p2pool_dir: &Path) -> Result<(), TomlError> {
use std::io::Write;
for file in GUPAX_P2POOL_API_FILE_ARRAY {
let mut path = gupax_p2pool_dir.clone();
let mut path = gupax_p2pool_dir.to_path_buf();
path.push(file);
if path.exists() {
info!(
Expand Down Expand Up @@ -1061,6 +1062,7 @@ impl Display for PayoutView {

//---------------------------------------------------------------------------------------------------- [Hash] enum for [Status/P2Pool]
#[derive(Clone, Copy, Eq, PartialEq, Debug, Deserialize, Serialize)]
#[allow(clippy::enum_variant_names)]
pub enum Hash {
Hash,
Kilo,
Expand Down Expand Up @@ -1229,8 +1231,7 @@ pub struct Xmrig {
pub selected_port: String,
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
#[derive(Default)]
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)]
pub struct Xvb {
pub token: u32,
}
Expand Down Expand Up @@ -1342,8 +1343,6 @@ impl Default for Xmrig {
}
}



impl Default for Version {
fn default() -> Self {
Self {
Expand Down
1 change: 1 addition & 0 deletions src/gupax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub enum Ratio {
//---------------------------------------------------------------------------------------------------- Gupax
impl crate::disk::Gupax {
#[inline(always)] // called once
#[allow(clippy::too_many_arguments)]
pub fn show(
&mut self,
og: &Arc<Mutex<State>>,
Expand Down
87 changes: 46 additions & 41 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::regex::{P2POOL_REGEX, XMRIG_REGEX};
use crate::{constants::*, human::*, macros::*, xmr::*, GupaxP2poolApi, RemoteNode, SudoState};
use log::*;
use serde::{Deserialize, Serialize};
use std::path::Path;
use std::{
fmt::Write,
path::PathBuf,
Expand Down Expand Up @@ -262,6 +263,7 @@ impl std::fmt::Display for ProcessName {
//---------------------------------------------------------------------------------------------------- [Helper]
impl Helper {
//---------------------------------------------------------------------------------------------------- General Functions
#[allow(clippy::too_many_arguments)]
pub fn new(
instant: std::time::Instant,
pub_sys: Arc<Mutex<Sys>>,
Expand Down Expand Up @@ -408,7 +410,7 @@ impl Helper {

// Read P2Pool/XMRig's API file to a [String].
fn path_to_string(
path: &std::path::PathBuf,
path: &Path,
name: ProcessName,
) -> std::result::Result<String, std::io::Error> {
match std::fs::read_to_string(path) {
Expand Down Expand Up @@ -437,7 +439,7 @@ impl Helper {
pub fn restart_p2pool(
helper: &Arc<Mutex<Self>>,
state: &crate::disk::P2pool,
path: &std::path::PathBuf,
path: &Path,
backup_hosts: Option<Vec<crate::Node>>,
) {
info!("P2Pool | Attempting to restart...");
Expand All @@ -446,7 +448,7 @@ impl Helper {

let helper = Arc::clone(helper);
let state = state.clone();
let path = path.clone();
let path = path.to_path_buf();
// This thread lives to wait, start p2pool then die.
thread::spawn(move || {
while lock2!(helper, p2pool).is_alive() {
Expand All @@ -466,7 +468,7 @@ impl Helper {
pub fn start_p2pool(
helper: &Arc<Mutex<Self>>,
state: &crate::disk::P2pool,
path: &std::path::PathBuf,
path: &Path,
backup_hosts: Option<Vec<crate::Node>>,
) {
lock2!(helper, p2pool).state = ProcessState::Middle;
Expand All @@ -488,7 +490,7 @@ impl Helper {
let gui_api = Arc::clone(&lock!(helper).gui_api_p2pool);
let pub_api = Arc::clone(&lock!(helper).pub_api_p2pool);
let gupax_p2pool_api = Arc::clone(&lock!(helper).gupax_p2pool_api);
let path = path.clone();
let path = path.to_path_buf();
thread::spawn(move || {
Self::spawn_p2pool_watchdog(
process,
Expand Down Expand Up @@ -523,11 +525,11 @@ impl Helper {
pub fn build_p2pool_args_and_mutate_img(
helper: &Arc<Mutex<Self>>,
state: &crate::disk::P2pool,
path: &std::path::PathBuf,
path: &Path,
backup_hosts: Option<Vec<crate::Node>>,
) -> (Vec<String>, PathBuf, PathBuf, PathBuf) {
let mut args = Vec::with_capacity(500);
let path = path.clone();
let path = path.to_path_buf();
let mut api_path = path;
api_path.pop();

Expand Down Expand Up @@ -684,6 +686,7 @@ impl Helper {
#[cold]
#[inline(never)]
// The P2Pool watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works.
#[allow(clippy::too_many_arguments)]
fn spawn_p2pool_watchdog(
process: Arc<Mutex<Process>>,
gui_api: Arc<Mutex<PubP2poolApi>>,
Expand Down Expand Up @@ -1039,7 +1042,7 @@ impl Helper {
pub fn restart_xmrig(
helper: &Arc<Mutex<Self>>,
state: &crate::disk::Xmrig,
path: &std::path::PathBuf,
path: &Path,
sudo: Arc<Mutex<SudoState>>,
) {
info!("XMRig | Attempting to restart...");
Expand All @@ -1048,7 +1051,7 @@ impl Helper {

let helper = Arc::clone(helper);
let state = state.clone();
let path = path.clone();
let path = path.to_path_buf();
// This thread lives to wait, start xmrig then die.
thread::spawn(move || {
while lock2!(helper, xmrig).state != ProcessState::Waiting {
Expand All @@ -1067,7 +1070,7 @@ impl Helper {
pub fn start_xmrig(
helper: &Arc<Mutex<Self>>,
state: &crate::disk::Xmrig,
path: &std::path::PathBuf,
path: &Path,
sudo: Arc<Mutex<SudoState>>,
) {
lock2!(helper, xmrig).state = ProcessState::Middle;
Expand All @@ -1082,7 +1085,7 @@ impl Helper {
let process = Arc::clone(&lock!(helper).xmrig);
let gui_api = Arc::clone(&lock!(helper).gui_api_xmrig);
let pub_api = Arc::clone(&lock!(helper).pub_api_xmrig);
let path = path.clone();
let path = path.to_path_buf();
thread::spawn(move || {
Self::spawn_xmrig_watchdog(process, gui_api, pub_api, args, path, sudo, api_ip_port);
});
Expand All @@ -1096,12 +1099,12 @@ impl Helper {
pub fn build_xmrig_args_and_mutate_img(
helper: &Arc<Mutex<Self>>,
state: &crate::disk::Xmrig,
path: &std::path::PathBuf,
path: &std::path::Path,
) -> (Vec<String>, String) {
let mut args = Vec::with_capacity(500);
let mut api_ip = String::with_capacity(15);
let mut api_port = String::with_capacity(5);
let path = path.clone();
let path = path.to_path_buf();
// The actual binary we're executing is [sudo], technically
// the XMRig path is just an argument to sudo, so add it.
// Before that though, add the ["--prompt"] flag and set it
Expand Down Expand Up @@ -1246,6 +1249,7 @@ impl Helper {
// The XMRig watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works.
// This isn't actually async, a tokio runtime is unfortunately needed because [Hyper] is an async library (HTTP API calls)
#[tokio::main]
#[allow(clippy::await_holding_lock)]
async fn spawn_xmrig_watchdog(
process: Arc<Mutex<Process>>,
gui_api: Arc<Mutex<PubXmrigApi>>,
Expand Down Expand Up @@ -1442,39 +1446,39 @@ impl Helper {
}

// Check vector of user input
let mut lock = lock!(process);
if !lock.input.is_empty() {
let input = std::mem::take(&mut lock.input);
for line in input {
if line.is_empty() {
continue;
}
debug!(
"XMRig Watchdog | User input not empty, writing to STDIN: [{}]",
line
);
#[cfg(target_os = "windows")]
if let Err(e) = write!(stdin, "{}\r\n", line) {
error!("XMRig Watchdog | STDIN error: {}", e);
}
#[cfg(target_family = "unix")]
if let Err(e) = writeln!(stdin, "{}", line) {
error!("XMRig Watchdog | STDIN error: {}", e);
}
// Flush.
if let Err(e) = stdin.flush() {
error!("XMRig Watchdog | STDIN flush error: {}", e);
{
let mut lock = lock!(process);
if !lock.input.is_empty() {
let input = std::mem::take(&mut lock.input);
for line in input {
if line.is_empty() {
continue;
}
debug!(
"XMRig Watchdog | User input not empty, writing to STDIN: [{}]",
line
);
#[cfg(target_os = "windows")]
if let Err(e) = write!(stdin, "{}\r\n", line) {
error!("XMRig Watchdog | STDIN error: {}", e);
}
#[cfg(target_family = "unix")]
if let Err(e) = writeln!(stdin, "{}", line) {
error!("XMRig Watchdog | STDIN error: {}", e);
}
// Flush.
if let Err(e) = stdin.flush() {
error!("XMRig Watchdog | STDIN flush error: {}", e);
}
}
}
}
drop(lock);

// Check if logs need resetting
debug!("XMRig Watchdog | Attempting GUI log reset check");
let mut lock = lock!(gui_api);
Self::check_reset_gui_output(&mut lock.output, ProcessName::Xmrig);
drop(lock);

{
let mut lock = lock!(gui_api);
Self::check_reset_gui_output(&mut lock.output, ProcessName::Xmrig);
}
// Always update from output
debug!("XMRig Watchdog | Starting [update_from_output()]");
PubXmrigApi::update_from_output(
Expand Down Expand Up @@ -1560,6 +1564,7 @@ impl Helper {
#[cold]
#[inline(never)]
// The "helper" thread. Syncs data between threads here and the GUI.
#[allow(clippy::await_holding_lock)]
pub fn spawn_helper(
helper: &Arc<Mutex<Self>>,
mut sysinfo: sysinfo::System,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,9 @@ fn init_logger(now: Instant) {
let dimmed = Style::new().dimmed();
writeln!(
buf,
"{level_style}[{}]{level_style:#} [{dimmed}{}{dimmed:#}] [{dimmed}{}{dimmed:#}:{dimmed}{}{dimmed:#}] {}",
"{level_style}[{}]{level_style:#} [{dimmed}{:.3}{dimmed:#}] [{dimmed}{}{dimmed:#}:{dimmed}{}{dimmed:#}] {}",
level,
format!("{:.3}", now.elapsed().as_secs_f32()),
now.elapsed().as_secs_f32(),
record.file().unwrap_or("???"),
record.line().unwrap_or(0),
record.args(),
Expand Down
5 changes: 2 additions & 3 deletions src/p2pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::sync::{Arc, Mutex};

impl crate::disk::P2pool {
#[inline(always)] // called once
#[allow(clippy::too_many_arguments)]
pub fn show(
&mut self,
node_vec: &mut Vec<(String, Node)>,
Expand Down Expand Up @@ -424,8 +425,7 @@ impl crate::disk::P2pool {
debug!("P2Pool Tab | Rendering [Node List]");
let text = RichText::new(format!("{}. {}", self.selected_index+1, self.selected_name));
ComboBox::from_id_source("manual_nodes").selected_text(text).width(width).show_ui(ui, |ui| {
let mut n = 0;
for (name, node) in node_vec.iter() {
for (n, (name, node)) in node_vec.iter().enumerate() {
let text = RichText::new(format!("{}. {}\n IP: {}\n RPC: {}\n ZMQ: {}", n+1, name, node.ip, node.rpc, node.zmq));
if ui.add(SelectableLabel::new(self.selected_name == *name, text)).clicked() {
self.selected_index = n;
Expand All @@ -439,7 +439,6 @@ impl crate::disk::P2pool {
self.rpc = node.rpc;
self.zmq = node.zmq;
}
n += 1;
}
});
// [Add/Save]
Expand Down
4 changes: 3 additions & 1 deletion src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ use crate::{
ImgXmrig, PayoutView, PubP2poolApi, PubXmrigApi, Submenu, Sys,
};
use egui::{
Hyperlink, Label, ProgressBar, RichText, SelectableLabel, Slider, Spinner, TextEdit, TextStyle, TextStyle::Name,
Hyperlink, Label, ProgressBar, RichText, SelectableLabel, Slider, Spinner, TextEdit, TextStyle,
TextStyle::Name,
};
use log::*;
use std::sync::{Arc, Mutex};

impl crate::disk::Status {
#[inline(always)] // called once
#[allow(clippy::too_many_arguments)]
pub fn show(
&mut self,
sys: &Arc<Mutex<Sys>>,
Expand Down
6 changes: 3 additions & 3 deletions src/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{constants::*, disk::Xmrig, macros::*, Helper, ProcessSignal};
use log::*;
use std::{
io::Write,
path::PathBuf,
path::Path,
process::*,
sync::{Arc, Mutex},
thread,
Expand Down Expand Up @@ -111,11 +111,11 @@ impl SudoState {
state: Arc<Mutex<Self>>,
helper: &Arc<Mutex<Helper>>,
xmrig: &Xmrig,
path: &PathBuf,
path: &Path,
) {
let helper = Arc::clone(helper);
let xmrig = xmrig.clone();
let path = path.clone();
let path = path.to_path_buf();
thread::spawn(move || {
// Set to testing
lock!(state).testing = true;
Expand Down
1 change: 1 addition & 0 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ impl Update {
// 3. if current == version, remove from vec
// 4. loop over vec, download links
// 5. extract, upgrade
#[allow(clippy::await_holding_lock)]
#[tokio::main]
pub async fn start(
update: Arc<Mutex<Self>>,
Expand Down
Loading

0 comments on commit ffceb4b

Please sign in to comment.