Skip to content

Commit 0160cb7

Browse files
committed
refactor(registry): Move IndexSummary filtering from Index to RegistrySource
1 parent 271df34 commit 0160cb7

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/cargo/sources/registry/index/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use std::collections::HashMap;
3737
use std::path::Path;
3838
use std::str;
3939
use std::task::{ready, Poll};
40-
use tracing::{debug, info};
40+
use tracing::info;
4141

4242
mod cache;
4343
use self::cache::CacheManager;
@@ -370,21 +370,7 @@ impl<'gctx> RegistryIndex<'gctx> {
370370
.filter_map(move |(k, v)| if req.matches(k) { Some(v) } else { None })
371371
.filter_map(move |maybe| {
372372
match maybe.parse(raw_data, source_id, bindeps) {
373-
Ok(sum @ IndexSummary::Candidate(_) | sum @ IndexSummary::Yanked(_)) => {
374-
Some(sum)
375-
}
376-
Ok(IndexSummary::Unsupported(summary, v)) => {
377-
debug!(
378-
"unsupported schema version {} ({} {})",
379-
v,
380-
summary.name(),
381-
summary.version()
382-
);
383-
None
384-
}
385-
Ok(IndexSummary::Offline(_)) => {
386-
unreachable!("We do not check for off-line until later")
387-
}
373+
Ok(sum) => Some(sum),
388374
Err(e) => {
389375
info!("failed to parse `{}` registry package: {}", name, e);
390376
None

src/cargo/sources/registry/mod.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,9 @@ impl<'gctx> Source for RegistrySource<'gctx> {
779779
ready!(self
780780
.index
781781
.query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| {
782-
if dep.matches(s.as_summary()) {
782+
if matches!(s, IndexSummary::Candidate(_) | IndexSummary::Yanked(_))
783+
&& dep.matches(s.as_summary())
784+
{
783785
// We are looking for a package from a lock file so we do not care about yank
784786
callback(s)
785787
}
@@ -813,13 +815,27 @@ impl<'gctx> Source for RegistrySource<'gctx> {
813815
// Next filter out all yanked packages. Some yanked packages may
814816
// leak through if they're in a whitelist (aka if they were
815817
// previously in `Cargo.lock`
816-
if !s.is_yanked() {
817-
callback(s);
818-
} else if self.yanked_whitelist.contains(&s.package_id()) {
819-
callback(s);
820-
} else if req.is_precise() {
821-
precise_yanked_in_use = true;
822-
callback(s);
818+
match s {
819+
s @ IndexSummary::Candidate(_) => callback(s),
820+
s @ IndexSummary::Yanked(_) => {
821+
if self.yanked_whitelist.contains(&s.package_id()) {
822+
callback(s);
823+
} else if req.is_precise() {
824+
precise_yanked_in_use = true;
825+
callback(s);
826+
}
827+
}
828+
IndexSummary::Unsupported(summary, v) => {
829+
tracing::debug!(
830+
"unsupported schema version {} ({} {})",
831+
v,
832+
summary.name(),
833+
summary.version()
834+
);
835+
}
836+
IndexSummary::Offline(summary) => {
837+
tracing::debug!("offline ({} {})", summary.name(), summary.version());
838+
}
823839
}
824840
}))?;
825841
if precise_yanked_in_use {

0 commit comments

Comments
 (0)