database now works with upgrading too(im sorry for the horrible code jnats)

i18n
axtlos 3 years ago
parent 05d8940b30
commit ea5f18af9e

@ -1,7 +1,30 @@
use crate::mods::strs::{err_unrec, inf, sec, succ}; //use crate::mods::strs::{err_unrec, inf, sec, succ};
use crate::{
err_unrec, inf, inssort, mods::strs::prompt, mods::strs::sec, mods::strs::succ,
mods::uninstall::uninstall, mods::database::addPkg
};
use runas::Command; use runas::Command;
use std::{env, fs}; use std::{env, fs, path::Path};
use toml; use toml;
use git2::Repository;
fn uninstall_make_depend(pkg: &str) {
let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone();
if make_depends.len() != 0 {
inf(format!(
"{} installed following make dependencies: {}",
pkg,
make_depends.join(", ")
));
let remove = prompt(format!("Would you like to remove them?"));
if remove == true {
uninstall(true, make_depends);
}
}
succ(format!("Succesfully upgraded {}", pkg));
}
pub fn upgrade(noconfirm: bool) { pub fn upgrade(noconfirm: bool) {
let homepath = std::env::var("HOME").unwrap(); let homepath = std::env::var("HOME").unwrap();
@ -48,71 +71,139 @@ pub fn upgrade(noconfirm: bool) {
println!("{:?}", dbParsed); println!("{:?}", dbParsed);
for entry in dbParsed.as_table() { for entry in dbParsed.as_table() {
for (key, value) in &*entry { for (key, value) in &*entry {
//println!("{} / {}", key, value); let results = raur::search(format!("{}",key));
for (option, entry) in { for res in results {
println!("{} / {}", option, entry); println!("{}",&res[0].name);
} let url = format!("https://aur.archlinux.org/{}.git", key);
//if key.contains("name") { let package = raur::info(&[key]).unwrap();
/* println!("{}",value); let version = value.to_string().replace("name", "").replace("version","").replace(" = ","").replace("\"","").replace(format!("{}",&res[0].name.to_string()).as_str(),"");
let results = raur::search(format!("{}",entry["paru"])); let name = value.to_string().replace("name", "").replace("version","").replace(" = ","").replace("\"","").replace(format!("{}",&res[0].version.to_string()).as_str(),"");
println!("{}",format!("{}",entry)); println!("{} / {}",name,version);
let mut test = value.to_string().replace("\"", ""); if res[0].version.contains(&version) {
test = test.replace("version", "").replace("name",""); let keydir = format!("{}{}",&cachedir,&key);
test = test.replace("=", ""); if std::path::Path::new(&keydir).is_dir() {
println!("{}",test.replace(" ",""));*/ let cd_result = env::set_current_dir(&keydir);
//let results = raur::search(format!("{}",value)); match cd_result {
//for res in results { Ok(_) => inf(format!("Entered package directory")),
// println!("{}",&res[0].name); Err(_) => err_unrec(format!("Could not enter package directory")),
//} }
/*} else if key.contains("version") { inssort(true, package[0].depends.clone());
if value.as_integer() == lVersion {
println!("upgrading");
}
}*/
}
}
/*for file in std::fs::read_dir(&cachedir).unwrap() { sec(format!("Installing {} ...", &key));
let dir = &file.unwrap().path(); let install_result = std::process::Command::new("makepkg")
let output = std::process::Command::new("git") .arg("-si")
.arg("pull") .arg("--noconfirm")
.output() .arg("--needed")
.unwrap(); .status();
let update_available = String::from_utf8(output.stdout).unwrap(); match install_result {
Ok(_) => {
uninstall_make_depend(&key);
}
Err(_) => {
err_unrec(format!("Couldn't install {}", &key));
}
};
let cd_result = env::set_current_dir(&dir); sec(format!("Installing {} ...", &key));
match cd_result { let install_result = std::process::Command::new("makepkg")
Ok(_) => inf(format!("Entered AUR package directory to pull changes")), .arg("-si")
Err(_) => err_unrec(format!( .arg("--needed")
"Could not enter AUR package directory to pull changes" .status()
)), .expect("Couldn't call makepkg");
} match install_result.code() {
Some(0) => {
uninstall_make_depend(&key);
}
Some(_) => {
err_unrec(format!("Couldn't install {}", &key));
}
None => {
err_unrec(format!("Couldn't install {}", &key));
}
};
} else {
inf(format!("Cloning {} ...", &key));
if update_available != "Already up to date." { if Path::new(&keydir).is_dir() {
let path_as_str = &dir.display().to_string(); let rm_result = fs::remove_dir_all(&keydir);
let pkg: Vec<&str> = path_as_str.split("/").collect(); match rm_result {
Ok(_) => inf(format!(
"Package path for {} already found. Removing to reinstall",
&key
)),
Err(_) => err_unrec(format!(
"Package path for {} already found, but could not remove to reinstall",
&key
)),
}
}
let dir_result = fs::create_dir(&keydir);
match dir_result {
Ok(_) => inf(format!("Created package directory for {}", &key)),
Err(_) => err_unrec(format!("Couldn't create package directory for {}", &key)),
}
let cd_result = env::set_current_dir(&keydir);
match cd_result {
Ok(_) => inf(format!("Entered package directory")),
Err(_) => err_unrec(format!("Could not enter package directory")),
}
inssort(true, package[0].depends.clone());
inf(format!("{} is up to date", pkg[pkg.len() - 1])); let clone = Repository::clone(&url, Path::new(&keydir));
} else { match clone {
let cd2_result = env::set_current_dir(&dir); Ok(_) => {
match cd2_result { inf(format!("Cloning {} into package directory", &key));
Ok(_) => inf(format!( }
"Entering AUR package directory to install new version" Err(_) => err_unrec(format!("Failed cloning {} into package directory", &key)),
)), }
Err(_) => err_unrec(format!( }
"Couldn't enter AUR package directory to install new version"
)),
}
let makepkg_result = std::process::Command::new("makepkg") sec(format!("Installing {} ...", &key));
.arg("-si") let install_result = std::process::Command::new("makepkg")
.status() .arg("-si")
.expect("Couldn't call makepkg"); .arg("--noconfirm")
match makepkg_result.code() { .arg("--needed")
Some(0) => succ(format!("New AUR package version installed")), .status();
Some(_) => err_unrec(format!("Couldn't install new AUR package version")), match install_result {
None => err_unrec(format!("Couldn't install new AUR package version")), Ok(_) => {
}; uninstall_make_depend(&key);
}
Err(_) => {
err_unrec(format!("Couldn't install {}", &key));
}
};
sec(format!("Installing {} ...", &key));
let install_result = std::process::Command::new("makepkg")
.arg("-si")
.arg("--needed")
.status()
.expect("Couldn't call makepkg");
match install_result.code() {
Some(0) => {
uninstall_make_depend(&key);
}
Some(_) => {
err_unrec(format!("Couldn't install {}", &key));
}
None => {
err_unrec(format!("Couldn't install {}", &key));
}
};
} else {
println!("not upgrading!");
if std::path::Path::new(&format!("{}{}",&cachedir,&key)).is_dir() {
println!("not cloning");
} else {
println!("cloning");
}
}
}
} }
}*/ }
} }

Loading…
Cancel
Save