♻ 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>,
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AlpmHelperResult {
NOTHING,
REMOVE,
ADD,
BOTH,
Nothing,
Remove,
Add,
Both,
}
impl AlpmHelper {
@ -30,23 +30,19 @@ impl AlpmHelper {
}
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() {
return result;
}
if !self.pkg_list_removal.is_empty() {
if self.install_apps(&self.pkg_list_removal, false) {
result = AlpmHelperResult::REMOVE;
if !self.pkg_list_removal.is_empty() && self.install_apps(&self.pkg_list_removal, false) {
result = AlpmHelperResult::Remove;
}
}
if !self.pkg_list_install.is_empty() {
if self.install_apps(&self.pkg_list_install, true) {
if result == AlpmHelperResult::NOTHING {
result = AlpmHelperResult::ADD;
if !self.pkg_list_install.is_empty() && self.install_apps(&self.pkg_list_install, true) {
if result == AlpmHelperResult::Nothing {
result = AlpmHelperResult::Add;
} 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) {
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();
self.pkg_list_removal.remove(index);
} else if !install && installed {
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();
self.pkg_list_install.remove(index);
} else if install && !installed {
@ -70,11 +66,11 @@ impl AlpmHelper {
}
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 {
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 {
@ -97,9 +93,6 @@ impl AlpmHelper {
let pacman =
pacmanconf::Config::with_opts(None, Some("/etc/pacman.conf"), Some("/")).unwrap();
let alpm = alpm_utils::alpm_with_conf(&pacman).unwrap();
match alpm.localdb().pkg(pkg_name) {
Ok(_) => true,
_ => false,
}
matches!(alpm.localdb().pkg(pkg_name), Ok(_))
}
}

View File

@ -10,7 +10,7 @@ use gtk::prelude::{
};
use once_cell::sync::Lazy;
use serde_json;
use std::fs;
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) {
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
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() {
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

View File

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