From f85b3c183cc6b8755a3bd4f4095f1488b9e4f72b Mon Sep 17 00:00:00 2001 From: ripytide Date: Sun, 17 Nov 2024 17:44:43 +0000 Subject: [PATCH] fix: add warning when arch packages are not found --- Cargo.lock | 7 +++++ Cargo.toml | 1 + src/backends/arch.rs | 64 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b88436b..11d9a6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -435,6 +435,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indoc" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" + [[package]] name = "is-terminal" version = "0.4.13" @@ -528,6 +534,7 @@ dependencies = [ "dirs", "home", "hostname", + "indoc", "itertools", "libc", "log", diff --git a/Cargo.toml b/Cargo.toml index 920e644..2f5d1bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ walkdir = "2.5.0" toml_edit = "0.22.22" tempfile = "3.14.0" strum = {version = "0.26.3", features = ["derive"]} +indoc = "2.0.5" [dev-dependencies] assert_cmd = "2.0.16" diff --git a/src/backends/arch.rs b/src/backends/arch.rs index 042b4d4..f4d17c1 100644 --- a/src/backends/arch.rs +++ b/src/backends/arch.rs @@ -68,29 +68,67 @@ impl Backend for Arch { } } - let mut final_packages = BTreeMap::new(); + let mut packages = { + let mut final_packages = BTreeMap::new(); - for (main_package, opts) in packages { - let overridden = final_packages - .insert(main_package.clone(), Self::InstallOptions::default()) - .is_some(); - - if overridden { - log::warn!("Package {main_package} overwrote another entry"); - } - - for package in opts.optional_deps.iter() { + for (package, install_options) in packages { let overridden = final_packages .insert(package.clone(), Self::InstallOptions::default()) .is_some(); if overridden { - log::warn!("Dependency {package} of {main_package} overwrote another entry"); + log::warn!("Package {package} overwrote another entry"); + } + + for dependency in install_options.optional_deps.iter() { + let overridden = final_packages + .insert(dependency.clone(), Self::InstallOptions::default()) + .is_some(); + + if overridden { + log::warn!("arch package {dependency} has been overridden by a dependency of the {package} package"); + } } } + + final_packages + }; + + let packages_cloned = packages.keys().cloned().collect::>(); + + for package in packages_cloned { + let is_real_package = run_command( + [ + config.arch_package_manager.as_command(), + "--sync", + "--info", + &package, + ], + Perms::Same, + ) + .is_ok(); + + if !is_real_package { + packages.remove(&package); + + log::warn!( + "{}", + indoc::formatdoc! {" + arch package {package} was not found as an available package and so was ignored, it may be due to one of the following issues: + - the package name has a typo as written in your group files + - the package is a virtual package (https://wiki.archlinux.org/title/Pacman#Virtual_packages) + and so is ambiguous. You can run `pacman -S {package}` to list non-virtual packages which + which supply the virtual package + - the package was removed from the repositories + - the package was renamed to a different name + - the local package database is out of date and so doesn't yet contain the package: + update it with `sudo pacman -Sy` + "} + ); + } } - Ok(final_packages) + Ok(packages) } fn query_installed_packages(config: &Config) -> Result> {