Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning when packages are not found #52

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
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
78 changes: 62 additions & 16 deletions src/backends/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,81 @@ 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");
}
}
}
}

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::<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 = 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 (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 -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` or similar command using your chosen AUR helper
"}
);
}
}

Ok(final_packages)
Ok(packages)
}

fn query_installed_packages(config: &Config) -> Result<BTreeMap<String, Self::QueryInfo>> {
Expand All @@ -111,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