Add confirmation for reinstalling of already installed packages

i18n
trivernis 2 years ago
parent 0f3133bf16
commit 98cc3e2388
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -8,6 +8,7 @@ pub struct PacmanInstallBuilder {
files: Vec<PathBuf>, files: Vec<PathBuf>,
as_deps: bool, as_deps: bool,
no_confirm: bool, no_confirm: bool,
needed: bool,
} }
impl PacmanInstallBuilder { impl PacmanInstallBuilder {
@ -44,6 +45,12 @@ impl PacmanInstallBuilder {
self self
} }
pub fn needed(mut self, needed: bool) -> Self {
self.needed = needed;
self
}
#[tracing::instrument(level = "debug")] #[tracing::instrument(level = "debug")]
pub async fn install(self) -> AppResult<()> { pub async fn install(self) -> AppResult<()> {
let mut command = ShellCommand::pacman().elevated(); let mut command = ShellCommand::pacman().elevated();
@ -61,9 +68,11 @@ impl PacmanInstallBuilder {
if self.as_deps { if self.as_deps {
command = command.arg("--asdeps") command = command.arg("--asdeps")
} }
if self.needed {
command = command.arg("--needed")
}
command command
.arg("--needed")
.args(self.packages) .args(self.packages)
.args(self.files) .args(self.files)
.wait_success() .wait_success()

@ -1,12 +1,14 @@
use std::collections::{HashMap, HashSet};
use aur_rpc::PackageInfo; use aur_rpc::PackageInfo;
use console::Alignment; use console::Alignment;
use crossterm::style::Stylize; use crossterm::style::Stylize;
use crate::internal::dependencies::DependencyInformation; use crate::{builder::pacman::PacmanQueryBuilder, internal::dependencies::DependencyInformation};
use super::get_logger; use super::get_logger;
pub fn print_dependency_list(dependencies: &[DependencyInformation]) -> bool { pub async fn print_dependency_list(dependencies: &[DependencyInformation]) -> bool {
let (deps_repo, makedeps_repo, deps_aur, makedeps_aur) = dependencies let (deps_repo, makedeps_repo, deps_aur, makedeps_aur) = dependencies
.iter() .iter()
.map(|d| { .map(|d| {
@ -39,7 +41,7 @@ pub fn print_dependency_list(dependencies: &[DependencyInformation]) -> bool {
if !deps_aur.is_empty() { if !deps_aur.is_empty() {
get_logger().print_newline(); get_logger().print_newline();
tracing::info!("AUR dependencies"); tracing::info!("AUR dependencies");
print_aur_package_list(&deps_aur); print_aur_package_list(&deps_aur).await;
empty = false; empty = false;
} }
@ -53,23 +55,45 @@ pub fn print_dependency_list(dependencies: &[DependencyInformation]) -> bool {
if !makedeps_aur.is_empty() { if !makedeps_aur.is_empty() {
get_logger().print_newline(); get_logger().print_newline();
tracing::info!("AUR make dependencies"); tracing::info!("AUR make dependencies");
print_aur_package_list(&makedeps_aur); print_aur_package_list(&makedeps_aur).await;
empty = false; empty = false;
} }
empty empty
} }
pub fn print_aur_package_list(packages: &[PackageInfo]) { pub async fn print_aur_package_list(packages: &[PackageInfo]) -> bool {
let pkgs = packages
.iter()
.map(|p| p.metadata.name.clone())
.collect::<HashSet<_>>();
let installed = PacmanQueryBuilder::all()
.query_with_output()
.await
.unwrap()
.into_iter()
.filter(|p| pkgs.contains(&p.name))
.map(|p| (p.name.clone(), p))
.collect::<HashMap<_, _>>();
get_logger().print_list( get_logger().print_list(
packages.iter().map(|pkg| { packages.iter().map(|pkg| {
format!( format!(
"{} version {} ({} votes)", "{} version {} ({} votes) {}",
console::pad_str(&pkg.metadata.name, 30, Alignment::Left, Some("...")).bold(), console::pad_str(&pkg.metadata.name, 30, Alignment::Left, Some("...")).bold(),
pkg.metadata.version.clone().dim(), pkg.metadata.version.clone().dim(),
pkg.metadata.num_votes, pkg.metadata.num_votes,
if installed.contains_key(&pkg.metadata.name) {
"(Installed)"
} else {
""
}
.bold()
.magenta()
) )
}), }),
"\n ", "\n ",
); );
!installed.is_empty()
} }

@ -104,8 +104,11 @@ pub async fn aur_install(packages: Vec<String>, options: Options) {
pb.finish_with_message("All packages found".green().to_string()); pb.finish_with_message("All packages found".green().to_string());
get_logger().reset_output_type(); get_logger().reset_output_type();
pb.finish_with_message("Found all packages in the aur"); if print_aur_package_list(&package_info).await && !options.noconfirm {
print_aur_package_list(&package_info); if !prompt!(default yes, "Some packages are already installed. Continue anyway?") {
cancelled!();
}
}
if !options.noconfirm { if !options.noconfirm {
let to_review = multi_select!(&packages, "Select packages to review"); let to_review = multi_select!(&packages, "Select packages to review");
@ -133,7 +136,7 @@ pub async fn aur_install(packages: Vec<String>, options: Options) {
.await .await
.silent_unwrap(AppExitCode::RpcError); .silent_unwrap(AppExitCode::RpcError);
print_dependency_list(&dependencies); print_dependency_list(&dependencies).await;
get_logger().new_multi_progress(); get_logger().new_multi_progress();
let contexts = future::try_join_all( let contexts = future::try_join_all(
@ -377,7 +380,7 @@ async fn install_packages(
ctx.step = BuildStep::Done; ctx.step = BuildStep::Done;
} }
install_opts.files(packages).install().await?; install_opts.files(packages).needed(false).install().await?;
Ok(ctxs) Ok(ctxs)
} }

Loading…
Cancel
Save