From a756c4a32f903e1bf8cbbe75d766c028bf070d5b Mon Sep 17 00:00:00 2001 From: ripytide Date: Sun, 17 Nov 2024 21:46:24 +0000 Subject: [PATCH] refactor: make log messages quote packages --- src/backends/all.rs | 4 ++-- src/backends/arch.rs | 45 +++++++++++++++++++++++++------------------- src/backends/dnf.rs | 6 +++--- src/core.rs | 4 ++-- src/groups.rs | 16 ++++++++-------- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/backends/all.rs b/src/backends/all.rs index 624536b..586d13e 100644 --- a/src/backends/all.rs +++ b/src/backends/all.rs @@ -125,8 +125,8 @@ macro_rules! package_ids { $( if !self.$lower_backend.is_empty() { writeln!(f, "[{}]", AnyBackend::$upper_backend)?; - for package_id in self.$lower_backend.iter() { - writeln!(f, "{package_id}")?; + for package in self.$lower_backend.iter() { + writeln!(f, "{package}")?; } writeln!(f)?; } diff --git a/src/backends/arch.rs b/src/backends/arch.rs index f4d17c1..f3e1e48 100644 --- a/src/backends/arch.rs +++ b/src/backends/arch.rs @@ -62,7 +62,7 @@ impl Backend for Arch { .is_some(); if overridden { - log::warn!("arch package {group_package} has been overridden by the {group} package group"); + log::warn!("arch package {group_package:?} has been overridden by the {group:?} package group"); } } } @@ -77,7 +77,7 @@ impl Backend for Arch { .is_some(); if overridden { - log::warn!("Package {package} overwrote another entry"); + log::warn!("Package {package:?} overwrote another entry"); } for dependency in install_options.optional_deps.iter() { @@ -86,7 +86,7 @@ impl Backend for Arch { .is_some(); if overridden { - log::warn!("arch package {dependency} has been overridden by a dependency of the {package} package"); + log::warn!("arch package {dependency:?} has been overridden by a dependency of the {package:?} package"); } } } @@ -96,17 +96,21 @@ impl Backend for Arch { let packages_cloned = packages.keys().cloned().collect::>(); + let all_packages: BTreeSet = run_command_for_stdout( + [ + config.arch_package_manager.as_command(), + "--sync", + "--list", + "--quiet", + ], + Perms::Same, + )? + .lines() + .map(String::from) + .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(); + let is_real_package = all_packages.contains(&package); if !is_real_package { packages.remove(&package); @@ -114,15 +118,18 @@ impl Backend for Arch { 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: + arch package {package:?} was not found as an available package and so was ignored (you can test + if the package exists via `pacman -Si {package:?}` or similar command using your chosen AUR helper) + + 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 + and so is ambiguous. You can run `pacman -Ss {package:?}` to list non-virtual packages which + which provide 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` + update it with `sudo pacman -Sy` or similar command using your chosen AUR helper "} ); } @@ -149,8 +156,8 @@ impl Backend for Arch { let mut result = BTreeMap::new(); - for package_id in explicit_packages.lines() { - result.insert(package_id.to_string(), ArchQueryInfo {}); + for package in explicit_packages.lines() { + result.insert(package.to_string(), ArchQueryInfo {}); } Ok(result) diff --git a/src/backends/dnf.rs b/src/backends/dnf.rs index c2ebb85..f1ac7b5 100644 --- a/src/backends/dnf.rs +++ b/src/backends/dnf.rs @@ -82,9 +82,9 @@ impl Backend for Dnf { .chain( packages .iter() - .flat_map(|(package_id, options)| match &options.repo { - Some(repo) => vec![package_id, "--repo", repo.as_str()], - None => vec![package_id.as_str()], + .flat_map(|(package, options)| match &options.repo { + Some(repo) => vec![package, "--repo", repo.as_str()], + None => vec![package.as_str()], }), ), Perms::Sudo, diff --git a/src/core.rs b/src/core.rs index a1b97a7..860ca9c 100644 --- a/src/core.rs +++ b/src/core.rs @@ -202,8 +202,8 @@ fn missing(managed: &InstallOptions, config: &Config) -> Result macro_rules! x { ($(($upper_backend:ident, $lower_backend:ident)),*) => { $( - for package_id in installed.$lower_backend { - missing.$lower_backend.remove(&package_id); + for package in installed.$lower_backend { + missing.$lower_backend.remove(&package); } )* }; diff --git a/src/groups.rs b/src/groups.rs index e07d211..7afaf95 100644 --- a/src/groups.rs +++ b/src/groups.rs @@ -39,9 +39,9 @@ impl Groups { macro_rules! x { ($(($upper_backend:ident, $lower_backend:ident)),*) => { $( - for package_id in raw_package_ids.$lower_backend { + for package in raw_package_ids.$lower_backend { reoriented - .entry((AnyBackend::$upper_backend, package_id.clone())) + .entry((AnyBackend::$upper_backend, package.clone())) .or_default() .entry(group_file.clone()) .or_default() @@ -54,9 +54,9 @@ impl Groups { } //warn the user about duplicated packages and output a deduplicated InstallOptions - for ((backend, package_id), group_files) in reoriented.iter() { + for ((backend, package), group_files) in reoriented.iter() { if group_files.len() > 1 { - log::warn!("duplicate {package_id:?} package in group files: {group_files:?} for the {backend} backend"); + log::warn!("duplicate {package:?} package in group files: {group_files:?} for the {backend} backend"); log::warn!("only one of the duplicated will be used which could may cause unintended behaviour if the duplicates have different install options"); } } @@ -144,9 +144,9 @@ fn parse_toml_key_value(group_file: &Path, key: &str, value: &Value) -> Result (x.to_string(), Default::default()), toml::Value::Table(x) => ( x.clone().try_into::()?.package, @@ -155,7 +155,7 @@ fn parse_toml_key_value(group_file: &Path, key: &str, value: &Value) -> Result return Err(eyre!("the {} backend in the {group_file:?} group file has a package which is neither a string or a table", $upper_backend)), }; - raw_install_options.$lower_backend.push((package_id, package_install_options)); + raw_install_options.$lower_backend.push((package, package_install_options)); } return Ok(raw_install_options);