Further split of aur_install

i18n
Michal S 2 years ago
parent 54c769a245
commit 978d276c18
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -23,6 +23,21 @@ pub fn init(options: Options) {
});
}
// If cache dir doesn't exist, create it
if !Path::new(&format!("{}/.cache/ame", homedir)).exists() {
if verbosity >= 1 {
log!("Initialising cache directory");
}
std::fs::create_dir_all(format!("{}/.cache/ame", homedir)).unwrap_or_else(|e| {
crash!(
AppExitCode::FailedCreatingPaths,
"Couldn't create path: {}/.cache/ame: {}",
homedir,
e,
);
});
}
// If config dir doesn't exist, create it
if !Path::new(&format!("{}/.config/ame/", homedir)).exists() {
if verbosity >= 1 {

@ -129,7 +129,8 @@ fn cmd_install(args: InstallArgs, options: Options, cachedir: &str) {
let out = std::process::Command::new("expac")
.args(&["-Q", "-l", "\n ", " %O", &p])
.output()
.unwrap().stdout;
.unwrap()
.stdout;
let out = String::from_utf8(out).unwrap().trim().to_string();
if !out.is_empty() {
info!("{}:", p);
@ -146,7 +147,7 @@ fn cmd_remove(args: RemoveArgs, options: Options) {
info!("Uninstalling packages: {}", &packages.join(", "));
// Remove packages
operations::uninstall(packages, options);
operations::uninstall(&packages, options);
}
fn cmd_search(args: &SearchArgs, options: Options) {

@ -10,6 +10,8 @@ use crate::internal::exit_code::AppExitCode;
use crate::internal::rpc::rpcinfo;
use crate::{crash, info, log, prompt, warn, Options};
const AUR_CACHE: &str = ".cache/ame";
fn list(dir: &str) -> Vec<String> {
let dirs = fs::read_dir(Path::new(&dir)).unwrap();
let dirs: Vec<String> = dirs
@ -120,7 +122,13 @@ fn finish(cachedir: &str, pkg: &str, options: &Options) {
.args(&[
"-cO",
"extglob",
format!("sudo pacman -U --asdeps {}/!({})/*.zst {}", cachedir, pkg, if options.noconfirm { "--noconfirm" } else { "" }).as_str(),
format!(
"sudo pacman -U --asdeps {}/!({})/*.zst {}",
cachedir,
pkg,
if options.noconfirm { "--noconfirm" } else { "" }
)
.as_str(),
])
.spawn()
.unwrap()
@ -129,7 +137,10 @@ fn finish(cachedir: &str, pkg: &str, options: &Options) {
if cmd.success() {
info!("All AUR dependencies installed");
} else {
crash!(AppExitCode::PacmanError, "AUR dependencies failed to install");
crash!(
AppExitCode::PacmanError,
"AUR dependencies failed to install"
);
}
}
@ -138,7 +149,13 @@ fn finish(cachedir: &str, pkg: &str, options: &Options) {
let cmd = std::process::Command::new("bash")
.args(&[
"-c",
format!("sudo pacman -U {}/{}/*.zst {}", cachedir, pkg, if options.noconfirm { "--noconfirm" } else { "" }).as_str(),
format!(
"sudo pacman -U {}/{}/*.zst {}",
cachedir,
pkg,
if options.noconfirm { "--noconfirm" } else { "" }
)
.as_str(),
])
.spawn()
.unwrap()
@ -151,9 +168,40 @@ fn finish(cachedir: &str, pkg: &str, options: &Options) {
}
}
fn clone(pkg: &String, pkgcache: &str) {
let url = crate::internal::rpc::URL;
// See if package is already cloned to AUR_CACHE
let dirs = list(pkgcache);
println!("{:?}", dirs);
if dirs.contains(pkg) {
// Enter directory and git pull
info!("Updating cached package source");
set_current_dir(Path::new(&format!(
"{}/{}/{}",
env::var("HOME").unwrap(),
AUR_CACHE,
pkg
)))
.unwrap();
ShellCommand::git()
.arg("pull")
.wait()
.silent_unwrap(AppExitCode::GitError);
} else {
// Clone package into cachedir
info!("Cloning package source");
set_current_dir(Path::new(&pkgcache)).unwrap();
ShellCommand::git()
.arg("clone")
.arg(format!("{}/{}", url, pkg))
.wait()
.silent_unwrap(AppExitCode::GitError);
}
}
pub fn aur_install(a: Vec<String>, options: Options, orig_cachedir: &str) {
// Initialise variables
let url = crate::internal::rpc::URL;
let cachedir = if options.asdeps || !orig_cachedir.is_empty() {
orig_cachedir.to_string()
} else {
@ -188,25 +236,29 @@ pub fn aur_install(a: Vec<String>, options: Options, orig_cachedir: &str) {
// Get package name
let pkg = &rpcres.package.as_ref().unwrap().name;
let pkgcache = format!("{}/{}", env::var("HOME").unwrap(), AUR_CACHE);
if verbosity >= 1 {
log!("Cloning {} into cachedir", pkg);
}
info!("Cloning package source");
// Clone package into cachedir
set_current_dir(Path::new(&cachedir)).unwrap();
ShellCommand::git()
.arg("clone")
.arg(format!("{}/{}", url, pkg))
clone(pkg, &pkgcache);
// Copy package from AUR_CACHE to cachedir
Command::new("cp")
.arg("-r")
.arg(format!(
"{}/{}/{}",
env::var("HOME").unwrap(),
AUR_CACHE,
pkg
))
.arg(format!("{}/{}", cachedir, pkg))
.spawn()
.unwrap()
.wait()
.silent_unwrap(AppExitCode::GitError);
if verbosity >= 1 {
log!(
"Cloned {} into cachedir, moving on to resolving dependencies: {:?}",
pkg,
rpcres.package
);
}
.unwrap();
// Sort dependencies and makedepends
if verbosity >= 1 {

@ -1,12 +1,9 @@
use std::path::Path;
use std::{env, fs};
use crate::internal::commands::ShellCommand;
use crate::internal::error::SilentUnwrap;
use crate::internal::exit_code::AppExitCode;
use crate::{log, Options};
pub fn uninstall(packages: Vec<String>, options: Options) {
pub fn uninstall(packages: &[String], options: Options) {
// Build pacman args
let mut pacman_args = vec!["-Rs"];
pacman_args.append(&mut packages.iter().map(String::as_str).collect());
@ -28,25 +25,4 @@ pub fn uninstall(packages: Vec<String>, options: Options) {
if verbosity >= 1 {
log!("Uninstalling packages: {:?} exited with code 0", &packages);
}
for package in packages {
// Remove old cache directory
if Path::new(&format!(
"{}/.cache/ame/{}",
env::var("HOME").unwrap(),
package
))
.exists()
{
if verbosity >= 1 {
log!("Old cache directory found, deleting");
}
fs::remove_dir_all(Path::new(&format!(
"{}/.cache/ame/{}",
env::var("HOME").unwrap(),
package
)))
.unwrap();
}
}
}

Loading…
Cancel
Save