diff --git a/src/clone.rs b/src/clone.rs index 39ec922..b994b53 100644 --- a/src/clone.rs +++ b/src/clone.rs @@ -1,6 +1,8 @@ use git2::Repository; use std::{fs, path::Path, process::exit}; use serde_json::Value; +use std::process::Command; +use std::io::{Error, ErrorKind}; pub fn clone(pkg: &str) { let url = format!("https://aur.archlinux.org/{}.git", pkg); @@ -8,20 +10,29 @@ pub fn clone(pkg: &str) { let homedir = std::env::var("HOME").unwrap(); let cachedir = format!("{}/.cache/ame/{}", homedir, pkg); let path = Path::new(&cachedir); + let errcode = Command::new("pacman").arg("-Ss").arg(&pkg).status().unwrap(); - if path.exists() { - fs::remove_dir_all(path).unwrap(); - } - - let aresp = ureq::get(&aurl).call().unwrap_or_else(|error| { - println!("{}", error); - exit(1); - }); - - if aresp.status() == 200 { - println!("Cloning {} ...", pkg); - Repository::clone(&url, &path).unwrap(); + if errcode.success() { + println!("found {} in repos!", &pkg); + Command::new("sudo").arg("pacman").arg("-S").arg(&pkg).spawn(); + } else { - println!("Error, repository {} not found", pkg); + println!("error"); + + if path.exists() { + fs::remove_dir_all(path).unwrap(); + } + + let aresp = ureq::get(&aurl).call().unwrap_or_else(|error| { + println!("{}", error); + exit(1); + }); + + if aresp.status() == 200 { + println!("Cloning {} ...", pkg); + Repository::clone(&url, &path).unwrap(); + } else { + println!("Error, repository {} not found", pkg); + } } } diff --git a/src/uninstall.rs b/src/uninstall.rs index 980411b..c28021c 100644 --- a/src/uninstall.rs +++ b/src/uninstall.rs @@ -2,9 +2,11 @@ use std::process::Command; pub fn uninstall(pkg: &str) { let errstr = format!("Could not remove package {}", pkg); - Command::new("pacman") + Command::new("sudo") + .arg("pacman") .arg("-R") .arg(&pkg) - .output() + .spawn() + //.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix .expect(&errstr); } diff --git a/src/upgrade.rs b/src/upgrade.rs index c59e375..805509d 100644 --- a/src/upgrade.rs +++ b/src/upgrade.rs @@ -4,6 +4,7 @@ pub fn upgrade() { let errstr = format!("Something happened"); Command::new("pacman") .arg("-Syu") - .output() + .spawn() + //.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix .expect(&errstr); } \ No newline at end of file