Skip to content

Commit

Permalink
move yank handling up
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Oct 24, 2023
1 parent a2bd2b9 commit e85a330
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 55 deletions.
32 changes: 5 additions & 27 deletions src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use serde::Deserialize;
use std::borrow::Cow;
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::fs;
use std::io::ErrorKind;
use std::path::Path;
Expand Down Expand Up @@ -574,8 +574,7 @@ impl<'cfg> RegistryIndex<'cfg> {
name: InternedString,
req: &OptVersionReq,
load: &mut dyn RegistryData,
yanked_whitelist: &HashSet<PackageId>,
f: &mut dyn FnMut(Summary),
f: &mut dyn FnMut(IndexSummary),
) -> Poll<CargoResult<()>> {
if self.config.offline() {
// This should only return `Poll::Ready(Ok(()))` if there is at least 1 match.
Expand All @@ -592,31 +591,15 @@ impl<'cfg> RegistryIndex<'cfg> {
let callback = &mut |s: IndexSummary| {
if !s.is_offline() {
called = true;
f(s.into_summary());
f(s);
}
};
ready!(self.query_inner_with_online(
name,
req,
load,
yanked_whitelist,
callback,
false
)?);
ready!(self.query_inner_with_online(name, req, load, callback, false)?);
if called {
return Poll::Ready(Ok(()));
}
}
self.query_inner_with_online(
name,
req,
load,
yanked_whitelist,
&mut |s| {
f(s.into_summary());
},
true,
)
self.query_inner_with_online(name, req, load, f, true)
}

/// Inner implementation of [`Self::query_inner`]. Returns the number of
Expand All @@ -628,7 +611,6 @@ impl<'cfg> RegistryIndex<'cfg> {
name: InternedString,
req: &OptVersionReq,
load: &mut dyn RegistryData,
yanked_whitelist: &HashSet<PackageId>,
f: &mut dyn FnMut(IndexSummary),
online: bool,
) -> Poll<CargoResult<()>> {
Expand All @@ -650,10 +632,6 @@ impl<'cfg> RegistryIndex<'cfg> {
IndexSummary::Offline(s.as_summary().clone())
}
})
// Next filter out all yanked packages. Some yanked packages may
// leak through if they're in a whitelist (aka if they were
// previously in `Cargo.lock`
.filter(|s| !s.is_yanked() || yanked_whitelist.contains(&s.package_id()))
.for_each(f);
Poll::Ready(Ok(()))
}
Expand Down
50 changes: 22 additions & 28 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,18 +730,15 @@ impl<'cfg> Source for RegistrySource<'cfg> {
if kind == QueryKind::Exact && req.is_locked() && !self.ops.is_updated() {
debug!("attempting query without update");
let mut called = false;
ready!(self.index.query_inner(
dep.package_name(),
&req,
&mut *self.ops,
&self.yanked_whitelist,
&mut |s| {
if dep.matches(&s) {
ready!(self
.index
.query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| {
if dep.matches(s.as_summary()) {
// We are looking for a package from a lock file so we do not care about yank
called = true;
f(s);
f(s.into_summary());
}
},
))?;
},))?;
if called {
Poll::Ready(Ok(()))
} else {
Expand All @@ -751,22 +748,23 @@ impl<'cfg> Source for RegistrySource<'cfg> {
}
} else {
let mut called = false;
ready!(self.index.query_inner(
dep.package_name(),
&req,
&mut *self.ops,
&self.yanked_whitelist,
&mut |s| {
ready!(self
.index
.query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| {
let matched = match kind {
QueryKind::Exact => dep.matches(&s),
QueryKind::Exact => dep.matches(s.as_summary()),
QueryKind::Fuzzy => true,
};
if matched {
f(s);
// Next filter out all yanked packages. Some yanked packages may
// leak through if they're in a whitelist (aka if they were
// previously in `Cargo.lock`
if matched
&& (!s.is_yanked() || self.yanked_whitelist.contains(&s.package_id()))
{
f(s.into_summary());
called = true;
}
}
))?;
}))?;
if called {
return Poll::Ready(Ok(()));
}
Expand All @@ -788,13 +786,9 @@ impl<'cfg> Source for RegistrySource<'cfg> {
}
any_pending |= self
.index
.query_inner(
name_permutation,
&req,
&mut *self.ops,
&self.yanked_whitelist,
f,
)?
.query_inner(name_permutation, &req, &mut *self.ops, &mut |s| {
f(s.into_summary());
})?
.is_pending();
}
}
Expand Down

0 comments on commit e85a330

Please sign in to comment.