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

fix and refactor cache_info_with_warnings #1290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 16 additions & 11 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,44 @@ pub async fn cache_info_with_warnings<'a, S: AsRef<str> + Send + Sync>(
let mut missing = Vec::new();
let mut ood = Vec::new();
let mut orphaned = Vec::new();
let mut aur_pkgs = raur.cache_info(cache, pkgs).await?;

let mut aur_pkgs = raur.cache_info(cache, pkgs).await?;
aur_pkgs.retain(|pkg1| pkgs.iter().any(|pkg2| pkg1.name == pkg2.as_ref()));

let should_warn =
|pkg: &str| !no_warn.is_match(pkg) && !ignore.iter().any(|ignored| ignored == pkg);

for pkg in pkgs {
if !no_warn.is_match(pkg.as_ref())
&& !ignore.iter().any(|p| p == pkg.as_ref())
&& !cache.contains(pkg.as_ref())
{
missing.push(pkg.as_ref())
let pkg_name = pkg.as_ref();
if should_warn(pkg_name) && !cache.contains(pkg_name) {
missing.push(pkg_name);
}
}

for pkg in &aur_pkgs {
if no_warn.is_match(&pkg.name) && !ignore.iter().any(|p| p.as_str() == pkg.name) {
if should_warn(&pkg.name) {
if pkg.out_of_date.is_some() {
ood.push(cache.get(pkg.name.as_str()).unwrap().name.as_str());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aur_pkgs comes from a call to raur.cache_info(). If a name is in the returned list it must also be in cache, so the unwraps are fine. Rest looks good to me,

if let Some(cached_pkg) = cache.get(pkg.name.as_str()) {
ood.push(cached_pkg.name.as_str());
}
}

if pkg.maintainer.is_none() {
orphaned.push(cache.get(pkg.name.as_str()).unwrap().name.as_str());
if let Some(cached_pkg) = cache.get(pkg.name.as_str()) {
orphaned.push(cached_pkg.name.as_str());
}
}
}
}

let ret = Warnings {
let warnings = Warnings {
pkgs: aur_pkgs,
missing,
ood,
orphans: orphaned,
};

Ok(ret)
Ok(warnings)
}

pub async fn getpkgbuilds(config: &mut Config) -> Result<i32> {
Expand Down