From 0b78a61cbb70ba486297b59e6089d80c6e78e5c8 Mon Sep 17 00:00:00 2001 From: Ponas Date: Fri, 3 Jul 2020 18:02:44 +0300 Subject: [PATCH] fixed user group warnings and removed deprecated Vec::remove_item --- src/main.rs | 24 ++++++++++++++++-------- src/state.rs | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0b7e5a0..2cffbe3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,10 +37,15 @@ fn main() { // Parse arguments let args = Opt::from_args(); - // Then make sure the user running this is in the group `wheel` - if !is_user_in_wheel() { + // Then make sure the user running this is in the group `wheel` and `network` + let (in_wheel, in_network) = is_user_in_wheel_and_network(); + if !in_wheel { eprintln!("Warning! You are not in group 'wheel', netctl-tray might not work or work only partially."); } + if !in_network { + eprintln!("Warning! You are not in group 'network', netctl-tray might not work or work only partially."); + } + let mut state = State { link_quality: 0, ping: 0.0, @@ -268,12 +273,12 @@ fn profile_notification( Ok(()) } -fn is_user_in_wheel() -> bool { +fn is_user_in_wheel_and_network() -> (bool, bool) { let username = match get_current_username() { Some(s) => s, None => { eprintln!("Can't get current user!"); - return false; + return (false, false); } }; @@ -281,18 +286,21 @@ fn is_user_in_wheel() -> bool { Some(g) => g, None => { eprintln!("Couldn't get the list of groups the user is in."); - return false; + return (false, false); } }; - // check if in wheel + let mut in_wheel = false; + let mut in_network = false; for group in groups { if group.name() == OsStr::new("network") { - return true; + in_network = true; + } else if group.name() == OsStr::new("wheel") { + in_wheel = true; } } - false + (in_wheel, in_network) } fn get_status_icon(state: &mut State) -> CppBox { diff --git a/src/state.rs b/src/state.rs index adcc4c0..5556565 100644 --- a/src/state.rs +++ b/src/state.rs @@ -46,7 +46,9 @@ pub fn inotify_watch( // Remove the profile for path in event.paths { match path.file_name().unwrap().to_str() { - Some(p) => all_profiles.lock().unwrap().remove_item(&p), + Some(p) => { + all_profiles.lock().unwrap().retain(|x| *x != p); + } None => { eprintln!( "Can't convert OsStr to str: {:?}",