Skip to content

Commit

Permalink
refactor: make log messages quote packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed Nov 19, 2024
1 parent 85308a9 commit 2c5fb0c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/backends/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
46 changes: 27 additions & 19 deletions src/backends/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand All @@ -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() {
Expand All @@ -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");
}
}
}
Expand All @@ -96,33 +96,41 @@ impl Backend for Arch {

let packages_cloned = packages.keys().cloned().collect::<Vec<_>>();

let all_packages: BTreeSet<String> = run_command_for_stdout(
[
config.arch_package_manager.as_command(),
"--sync",
"--list",
"--quiet",
],
Perms::Same,
false,
)?
.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);

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
"}
);
}
Expand All @@ -149,8 +157,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)
Expand Down
6 changes: 3 additions & 3 deletions src/backends/dnf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ fn missing(managed: &InstallOptions, config: &Config) -> Result<InstallOptions>
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);
}
)*
};
Expand Down
16 changes: 8 additions & 8 deletions src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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");
}
}
Expand Down Expand Up @@ -144,9 +144,9 @@ fn parse_toml_key_value(group_file: &Path, key: &str, value: &Value) -> Result<R
eyre!("the {} backend in the {group_file:?} group file has a non-array value", $upper_backend)
)?;

for package_id in packages {
let (package_id, package_install_options) =
match package_id {
for package in packages {
let (package, package_install_options) =
match package {
toml::Value::String(x) => (x.to_string(), Default::default()),
toml::Value::Table(x) => (
x.clone().try_into::<StringPackageStruct>()?.package,
Expand All @@ -155,7 +155,7 @@ fn parse_toml_key_value(group_file: &Path, key: &str, value: &Value) -> Result<R
_ => 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);
Expand Down

0 comments on commit 2c5fb0c

Please sign in to comment.