♻ Make clippy happy

This commit is contained in:
Vladislav Nepogodin 2022-07-05 03:57:55 +04:00
parent e176a74b51
commit b80bfe5d3f
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
3 changed files with 23 additions and 30 deletions

View File

@ -7,12 +7,12 @@ pub struct AlpmHelper {
pub pkg_list_removal: Vec<String>, pub pkg_list_removal: Vec<String>,
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum AlpmHelperResult { pub enum AlpmHelperResult {
NOTHING, Nothing,
REMOVE, Remove,
ADD, Add,
BOTH, Both,
} }
impl AlpmHelper { impl AlpmHelper {
@ -30,23 +30,19 @@ impl AlpmHelper {
} }
pub fn do_update(&self) -> AlpmHelperResult { pub fn do_update(&self) -> AlpmHelperResult {
let mut result = AlpmHelperResult::NOTHING; let mut result = AlpmHelperResult::Nothing;
if self.pkg_list_install.is_empty() && self.pkg_list_removal.is_empty() { if self.pkg_list_install.is_empty() && self.pkg_list_removal.is_empty() {
return result; return result;
} }
if !self.pkg_list_removal.is_empty() { if !self.pkg_list_removal.is_empty() && self.install_apps(&self.pkg_list_removal, false) {
if self.install_apps(&self.pkg_list_removal, false) { result = AlpmHelperResult::Remove;
result = AlpmHelperResult::REMOVE;
}
} }
if !self.pkg_list_install.is_empty() { if !self.pkg_list_install.is_empty() && self.install_apps(&self.pkg_list_install, true) {
if self.install_apps(&self.pkg_list_install, true) { if result == AlpmHelperResult::Nothing {
if result == AlpmHelperResult::NOTHING { result = AlpmHelperResult::Add;
result = AlpmHelperResult::ADD; } else {
} else { result = AlpmHelperResult::Both;
result = AlpmHelperResult::BOTH;
}
} }
} }
@ -54,14 +50,14 @@ impl AlpmHelper {
} }
pub fn set_package(&mut self, pkg_name: &String, install: bool, installed: bool) { pub fn set_package(&mut self, pkg_name: &String, install: bool, installed: bool) {
if self.to_remove(&pkg_name) { if self.to_remove(pkg_name) {
let index = self.pkg_list_removal.iter().position(|x| *x == *pkg_name).unwrap(); let index = self.pkg_list_removal.iter().position(|x| *x == *pkg_name).unwrap();
self.pkg_list_removal.remove(index); self.pkg_list_removal.remove(index);
} else if !install && installed { } else if !install && installed {
self.pkg_list_removal.push(String::from(pkg_name)); self.pkg_list_removal.push(String::from(pkg_name));
} }
if self.to_install(&pkg_name) { if self.to_install(pkg_name) {
let index = self.pkg_list_install.iter().position(|x| *x == *pkg_name).unwrap(); let index = self.pkg_list_install.iter().position(|x| *x == *pkg_name).unwrap();
self.pkg_list_install.remove(index); self.pkg_list_install.remove(index);
} else if install && !installed { } else if install && !installed {
@ -70,11 +66,11 @@ impl AlpmHelper {
} }
pub fn to_install(&self, pkg_name: &String) -> bool { pub fn to_install(&self, pkg_name: &String) -> bool {
self.pkg_list_install.contains(&pkg_name) self.pkg_list_install.contains(pkg_name)
} }
pub fn to_remove(&self, pkg_name: &String) -> bool { pub fn to_remove(&self, pkg_name: &String) -> bool {
self.pkg_list_removal.contains(&pkg_name) self.pkg_list_removal.contains(pkg_name)
} }
fn install_apps(&self, pkg_list: &Vec<String>, install: bool) -> bool { fn install_apps(&self, pkg_list: &Vec<String>, install: bool) -> bool {
@ -97,9 +93,6 @@ impl AlpmHelper {
let pacman = let pacman =
pacmanconf::Config::with_opts(None, Some("/etc/pacman.conf"), Some("/")).unwrap(); pacmanconf::Config::with_opts(None, Some("/etc/pacman.conf"), Some("/")).unwrap();
let alpm = alpm_utils::alpm_with_conf(&pacman).unwrap(); let alpm = alpm_utils::alpm_with_conf(&pacman).unwrap();
match alpm.localdb().pkg(pkg_name) { matches!(alpm.localdb().pkg(pkg_name), Ok(_))
Ok(_) => true,
_ => false,
}
} }
} }

View File

@ -10,7 +10,7 @@ use gtk::prelude::{
}; };
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use serde_json;
use std::fs; use std::fs;
use std::sync::Mutex; use std::sync::Mutex;
@ -389,7 +389,7 @@ fn on_app_toggle(_cell: &gtk::CellRendererToggle, path: gtk::TreePath) {
fn on_update_system_clicked(_: &gtk::Button) { fn on_update_system_clicked(_: &gtk::Button) {
let app_browser = unsafe { &mut G_APP_BROWSER.lock().unwrap() }; let app_browser = unsafe { &mut G_APP_BROWSER.lock().unwrap() };
if app_browser.alpm_helper.do_update() != AlpmHelperResult::NOTHING { if app_browser.alpm_helper.do_update() != AlpmHelperResult::Nothing {
// reload json for view new apps installed // reload json for view new apps installed
app_browser.reload_app_data(true); app_browser.reload_app_data(true);
} }
@ -402,7 +402,7 @@ fn load_groups_data(groups: &serde_json::Value) -> gtk::ListStore {
for group in groups.as_array().unwrap() { for group in groups.as_array().unwrap() {
let g_name = String::from(group["name"].as_str().unwrap()); let g_name = String::from(group["name"].as_str().unwrap());
store.set(&store.append(), &[(0, &String::from(g_name))]); store.set(&store.append(), &[(0, &g_name)]);
} }
store store

View File

@ -89,8 +89,8 @@ mod test {
#[test] #[test]
fn check_file() { fn check_file() {
assert_eq!(check_regular_file("/etc/fstab"), true); assert!(check_regular_file("/etc/fstab"));
assert_eq!(check_regular_file("/etc"), false); assert!(!check_regular_file("/etc"));
} }
#[test] #[test]