diff --git a/.gitignore b/.gitignore index ea11fc5..c43a208 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target/ Cargo.lock -ame \ No newline at end of file +ame +.vscode diff --git a/Cargo.toml b/Cargo.toml index 0cbab8f..8ea74d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,5 @@ git2 = "*" raur = "2.0.2" runas = "*" toml = "*" -serde = "*" \ No newline at end of file +serde = "*" +walkdir = "*" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ccfba35..e9ae8f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,8 +51,9 @@ fn main() { help(); exit(1); } + let oper = &args[1]; - let clone_path=configfile.cache.unwrap(); + let cache_path=configfile.cache.unwrap(); if oper == "-S" || oper == "ins" || oper == "install" { for arg in env::args().skip(2) { if configfile.backends.pacman.unwrap() == true { @@ -62,7 +63,7 @@ fn main() { install(configoption_noconfirm, &arg); } else { if configfile.backends.aur.unwrap() == true { - clone(&arg, &clone_path); + clone(&arg, &cache_path); } else { println!("ERROR: the package wasn't found in the repos and aur support is disabled"); println!("Please enable aur support if you wish to check if this package exists in the aur"); @@ -70,7 +71,7 @@ fn main() { } } } else if configfile.backends.aur.unwrap() == true { - clone(&arg, &clone_path) + clone(&arg, &cache_path) } else { println!("ERROR: it seems like neither pacman, nor aur support is enabled!"); println!("Please enable either one of those option and try again"); @@ -84,7 +85,7 @@ fn main() { } } else if oper == "-Syu" || oper=="upg" || oper=="upgrade" { let configoption_noconfirm = configfile.pacman.noconfirm.unwrap(); - upgrade(configoption_noconfirm); + upgrade(configoption_noconfirm, &cache_path); } else if oper == "-Ss" || oper=="sear" || oper=="search" { for arg in env::args().skip(2) { r_search(&arg); diff --git a/src/mods/clone.rs b/src/mods/clone.rs index 65f920a..425fb3c 100644 --- a/src/mods/clone.rs +++ b/src/mods/clone.rs @@ -1,19 +1,21 @@ use git2::Repository; -use std::{fs, path::Path, process::Command}; +use std::{env, fs, path::Path, process::Command}; 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); + env::set_current_dir(&pkgdir); + fs::create_dir(&pkg); let results = raur::search(&pkg).expect(&error); let url = format!("https://aur.archlinux.org/{}.git", results[0].name); - if path.exists() { - fs::remove_dir_all(path).unwrap(); - } println!("Cloning {} ...", pkg); - Repository::clone(&url, &path).unwrap(); + println!("{}", &cachedir); + Repository::clone(&url, &pkgpath).unwrap(); + env::set_current_dir(&pkgpath); println!("Installing {} ...", pkg); Command::new("makepkg") - .current_dir(&cachedir) .arg("-si") .status() .expect(&error); diff --git a/src/mods/upgrade.rs b/src/mods/upgrade.rs index 3804b21..adb3c51 100644 --- a/src/mods/upgrade.rs +++ b/src/mods/upgrade.rs @@ -1,6 +1,9 @@ use runas::Command; +use walkdir::WalkDir; +use git2::Repository; +use std::{path, env}; -pub fn upgrade(noconfirm: bool) { +pub fn upgrade(noconfirm: bool, cachedir: &str){ let errstr = format!("Something happened"); if noconfirm == true { Command::new("pacman") @@ -14,4 +17,18 @@ pub fn upgrade(noconfirm: bool) { .status() .expect(&errstr); } -} + 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 update_available = String::from_utf8(output.stdout).unwrap(); + if update_available != "Already up to date." { + let path_as_str = &dir.display().to_string(); + let pkg: Vec<&str> = path_as_str.split("/").collect(); + println!("{} is up to date", pkg[pkg.len()-1]); + } else { + env::set_current_dir(&dir); + std::process::Command::new("makepkg").arg("-si"); + } + } +}