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

@ -1,12 +1,14 @@
use std::collections::{HashMap, HashSet};
use aur_rpc::PackageInfo;
use console::Alignment;
use crossterm::style::Stylize;
use crate::internal::dependencies::DependencyInformation;
use crate::{builder::pacman::PacmanQueryBuilder, internal::dependencies::DependencyInformation};
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
.iter()
.map(|d| {
@ -39,7 +41,7 @@ pub fn print_dependency_list(dependencies: &[DependencyInformation]) -> bool {
if !deps_aur.is_empty() {
get_logger().print_newline();
tracing::info!("AUR dependencies");
print_aur_package_list(&deps_aur);
print_aur_package_list(&deps_aur).await;
empty = false;
}
@ -53,23 +55,45 @@ pub fn print_dependency_list(dependencies: &[DependencyInformation]) -> bool {
if !makedeps_aur.is_empty() {
get_logger().print_newline();
tracing::info!("AUR make dependencies");
print_aur_package_list(&makedeps_aur);
print_aur_package_list(&makedeps_aur).await;
empty = false;
}
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(
packages.iter().map(|pkg| {
format!(
"{} version {} ({} votes)",
"{} version {} ({} votes) {}",
console::pad_str(&pkg.metadata.name, 30, Alignment::Left, Some("...")).bold(),
pkg.metadata.version.clone().dim(),
pkg.metadata.num_votes,
if installed.contains_key(&pkg.metadata.name) {
"(Installed)"
} else {
""
}
.bold()
.magenta()
)
}),
"\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());
get_logger().reset_output_type();
pb.finish_with_message("Found all packages in the aur");
print_aur_package_list(&package_info);
if print_aur_package_list(&package_info).await && !options.noconfirm {
if !prompt!(default yes, "Some packages are already installed. Continue anyway?") {
cancelled!();
}
}
if !options.noconfirm {
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
.silent_unwrap(AppExitCode::RpcError);
print_dependency_list(&dependencies);
print_dependency_list(&dependencies).await;
get_logger().new_multi_progress();
let contexts = future::try_join_all(
@ -377,7 +380,7 @@ async fn install_packages(
ctx.step = BuildStep::Done;
}
install_opts.files(packages).install().await?;
install_opts.files(packages).needed(false).install().await?;
Ok(ctxs)
}

Loading…
Cancel
Save