diff --git a/src/main.rs b/src/main.rs index e9ae8f9..e06e815 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,27 @@ use serde; use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, flatpak::flatpak, config::printconfig}; use std::{fs, fs::File, io::prelude::*, env, process::exit, process::Command}; +// Code audit notes from axtlos: +/* Maybe we could change the code style for the if..elif..else structure so that it isnt +if { + +} elif { + +} + +but rather +if +{ + +} elif +{ + +} +So that the code is a bit more readable + +We should also check where we can "merge" variables or create new ones + +*/ #[derive(serde::Deserialize)] struct General { cache: Option, @@ -25,7 +46,7 @@ struct Pacman { fn main() { let args: Vec = env::args().collect(); - let mut confile = File::open("/etc/ame.toml").expect("Unable to open the Config file, did you delete ame.toml from /etc/??"); + let mut confile = File::open("/etc/ame.toml").expect("Unable to open the Config file, did you delete ame.toml from /etc/"); let mut config = String::new(); let defaultconfig = format!(r#" cache = "{}/.cache/ame" @@ -40,7 +61,7 @@ fn main() { "#, std::env::var("HOME").unwrap()); let mut configfile: General = toml::from_str(&defaultconfig).unwrap(); - if fs::read_to_string("/etc/ame.toml").expect("unable to open config file! (/etc/ame.toml)") != "" { + if fs::read_to_string("/etc/ame.toml").expect("unable to open config file! (/etc/ame.toml)") != "" { //maybe print out a warning when the config file is empty so that the user knows the hardcoded one is being used confile.read_to_string(&mut config).expect("Unable to read the Config file (/etc/ame.toml)"); let homepath = std::env::var("HOME").unwrap(); config=config.replace("~", &homepath); @@ -57,7 +78,7 @@ fn main() { if oper == "-S" || oper == "ins" || oper == "install" { for arg in env::args().skip(2) { if configfile.backends.pacman.unwrap() == true { - let out = Command::new("pacman").arg("-Ss").arg(&arg).status().unwrap(); + let out = Command::new("pacman").arg("-Ss").arg(&arg).status().unwrap(); // How do we silence this command?? using > /dev/null seems to also silence the returncode which is needed here if out.success() { let configoption_noconfirm = configfile.pacman.noconfirm.unwrap(); install(configoption_noconfirm, &arg); diff --git a/src/mods/clone.rs b/src/mods/clone.rs index 425fb3c..06dbdf6 100644 --- a/src/mods/clone.rs +++ b/src/mods/clone.rs @@ -1,11 +1,19 @@ use git2::Repository; use std::{env, fs, path::Path, process::Command}; +// Code audit notes from axtlos: +/* + try to resolve the warning because of unused std::result::Result, no idea how to do that +*/ + pub fn clone(pkg: &str, cachedir: &str) { let error = format!("Couldn't install {}", &pkg); let path = Path::new(&cachedir); let pkgdir=format!("{}/{}", &cachedir, &pkg); let pkgpath = Path::new(&pkgdir); + if !path.is_dir() { + fs::create_dir(&path); + } env::set_current_dir(&pkgdir); fs::create_dir(&pkg); let results = raur::search(&pkg).expect(&error); diff --git a/src/mods/config.rs b/src/mods/config.rs index d995e3c..cbd6f3e 100644 --- a/src/mods/config.rs +++ b/src/mods/config.rs @@ -39,7 +39,7 @@ pub fn printconfig() { noconfirm = false "#, std::env::var("HOME").unwrap()); let mut configfile: General = toml::from_str(&defaultconfig).unwrap(); - if fs::read_to_string("/etc/ame.toml").expect("unable to open config file! (/etc/ame.toml)") != "" { + if fs::read_to_string("/etc/ame.toml").expect("unable to open config file! (/etc/ame.toml)") != "" { //maybe print out a warning when the config file is empty so that the user knows the hardcoded one is being used confile.read_to_string(&mut config).expect("Unable to read the Config file (/etc/ame.toml)"); let homepath = std::env::var("HOME").unwrap(); config=config.replace("~", &homepath); diff --git a/src/mods/help.rs b/src/mods/help.rs index 77e1342..2d7a181 100644 --- a/src/mods/help.rs +++ b/src/mods/help.rs @@ -1,4 +1,4 @@ -pub fn help() { +pub fn help() { // work on a proper error message, the python ame one isnt really better in my opinion println!("\ Usage:\n ame -S - install a package diff --git a/src/mods/install.rs b/src/mods/install.rs index 7911560..d68b946 100644 --- a/src/mods/install.rs +++ b/src/mods/install.rs @@ -2,7 +2,7 @@ use runas::Command; pub fn install(noconfirm: bool, pkg: &str) { println!("{}",noconfirm); - let errstr = format!("Oops.. Something went wrong!"); + let errstr = format!("Oops.. Something went wrong!"); // we should make one set way of how error messages are written if noconfirm == false { Command::new("pacman").arg("-S").arg(&pkg).status().expect(&errstr); } else { diff --git a/src/mods/search.rs b/src/mods/search.rs index a60bf67..6457eb7 100644 --- a/src/mods/search.rs +++ b/src/mods/search.rs @@ -3,7 +3,7 @@ use std::{ops::Deref, process::Command}; pub fn a_search(pkg: &str) { let results = raur::search(&pkg); for res in &results { - println!("aur/{} {}\n {}", res[0].name, res[0].version, res[0].description.as_ref().map_or("n/a", String::deref)); + println!("aur/{} {}\n {}", res[0].name, res[0].version, res[0].description.as_ref().map_or("n/a", String::deref)); //i like your funny words, magic man (seriously, what does this do??) } } diff --git a/src/mods/uninstall.rs b/src/mods/uninstall.rs index 7d97330..dacad55 100644 --- a/src/mods/uninstall.rs +++ b/src/mods/uninstall.rs @@ -1,7 +1,7 @@ use runas::Command; pub fn uninstall(noconfirm: bool, pkg: &str) { - let errstr = format!("Could not remove package {}", pkg); + let errstr = format!("Could not remove package {}", pkg); //again, we should choose one way to do error messages if noconfirm == false { Command::new("pacman").arg("-R").arg(&pkg).status().expect(&errstr); diff --git a/src/mods/upgrade.rs b/src/mods/upgrade.rs index adb3c51..49b3a3b 100644 --- a/src/mods/upgrade.rs +++ b/src/mods/upgrade.rs @@ -1,8 +1,9 @@ use runas::Command; -use walkdir::WalkDir; use git2::Repository; use std::{path, env}; +// fix unused std::result::Result + pub fn upgrade(noconfirm: bool, cachedir: &str){ let errstr = format!("Something happened"); if noconfirm == true { @@ -20,7 +21,7 @@ pub fn upgrade(noconfirm: bool, cachedir: &str){ for file in std::fs::read_dir(&cachedir).unwrap() { let dir = &file.unwrap().path(); env::set_current_dir(&dir); - let output = std::process::Command::new("git").arg("pull").output().unwrap(); + let output = std::process::Command::new("git").arg("pull").output().unwrap(); //figure out how to pull with the git2 crate! let update_available = String::from_utf8(output.stdout).unwrap(); if update_available != "Already up to date." { let path_as_str = &dir.display().to_string(); @@ -28,7 +29,7 @@ pub fn upgrade(noconfirm: bool, cachedir: &str){ println!("{} is up to date", pkg[pkg.len()-1]); } else { env::set_current_dir(&dir); - std::process::Command::new("makepkg").arg("-si"); + std::process::Command::new("makepkg").arg("-si").status(); } } }