From 4a2f810deb46c73d62307d71db01f6b408556a27 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 2 Feb 2019 10:44:19 -0800 Subject: [PATCH] Update existing sources when whitelist modified When sources already exist in a `PackageRegistry` and the whitelist is updated in the package registry, be sure to update all the existing sources to ensure that everyone gets the same view of the intended whitelist. --- src/cargo/core/registry.rs | 6 +++++- src/cargo/core/source/mod.rs | 13 +++++++++++++ src/cargo/sources/directory.rs | 2 ++ src/cargo/sources/git/source.rs | 2 ++ src/cargo/sources/path.rs | 2 ++ src/cargo/sources/registry/index.rs | 6 +++++- src/cargo/sources/registry/mod.rs | 4 ++++ src/cargo/sources/replaced.rs | 6 ++++++ 8 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index f74b507a89b..bc1667071ae 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -169,7 +169,11 @@ impl<'cfg> PackageRegistry<'cfg> { } pub fn add_to_yanked_whitelist(&mut self, iter: impl Iterator) { - self.yanked_whitelist.extend(iter) + let pkgs = iter.collect::>(); + for (_, source) in self.sources.sources_mut() { + source.add_to_yanked_whitelist(&pkgs); + } + self.yanked_whitelist.extend(pkgs); } pub fn register_lock(&mut self, id: PackageId, deps: Vec) { diff --git a/src/cargo/core/source/mod.rs b/src/cargo/core/source/mod.rs index 62583147c99..50d1c63d869 100644 --- a/src/cargo/core/source/mod.rs +++ b/src/cargo/core/source/mod.rs @@ -83,6 +83,11 @@ pub trait Source { fn is_replaced(&self) -> bool { false } + + /// Add a number of crates that should be whitelisted for showing up during + /// queries, even if they are yanked. Currently only applies to registry + /// sources. + fn add_to_yanked_whitelist(&mut self, pkgs: &[PackageId]); } pub enum MaybePackage { @@ -152,6 +157,10 @@ impl<'a, T: Source + ?Sized + 'a> Source for Box { fn is_replaced(&self) -> bool { (**self).is_replaced() } + + fn add_to_yanked_whitelist(&mut self, pkgs: &[PackageId]) { + (**self).add_to_yanked_whitelist(pkgs); + } } impl<'a, T: Source + ?Sized + 'a> Source for &'a mut T { @@ -206,6 +215,10 @@ impl<'a, T: Source + ?Sized + 'a> Source for &'a mut T { fn is_replaced(&self) -> bool { (**self).is_replaced() } + + fn add_to_yanked_whitelist(&mut self, pkgs: &[PackageId]) { + (**self).add_to_yanked_whitelist(pkgs); + } } /// A `HashMap` of `SourceId` -> `Box` diff --git a/src/cargo/sources/directory.rs b/src/cargo/sources/directory.rs index c1a4b4dc771..8009a149dc0 100644 --- a/src/cargo/sources/directory.rs +++ b/src/cargo/sources/directory.rs @@ -214,4 +214,6 @@ impl<'cfg> Source for DirectorySource<'cfg> { fn describe(&self) -> String { format!("directory source `{}`", self.root.display()) } + + fn add_to_yanked_whitelist(&mut self, _pkgs: &[PackageId]) {} } diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index 9b96ede0308..ff60990254f 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -238,6 +238,8 @@ impl<'cfg> Source for GitSource<'cfg> { fn describe(&self) -> String { format!("git repository {}", self.source_id) } + + fn add_to_yanked_whitelist(&mut self, _pkgs: &[PackageId]) {} } #[cfg(test)] diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index e95ccd7bf67..9ec74851233 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -569,4 +569,6 @@ impl<'cfg> Source for PathSource<'cfg> { Err(_) => self.source_id.to_string(), } } + + fn add_to_yanked_whitelist(&mut self, _pkgs: &[PackageId]) {} } diff --git a/src/cargo/sources/registry/index.rs b/src/cargo/sources/registry/index.rs index 51b39c5ae99..249eb65f79a 100644 --- a/src/cargo/sources/registry/index.rs +++ b/src/cargo/sources/registry/index.rs @@ -282,7 +282,11 @@ impl<'cfg> RegistryIndex<'cfg> { let summaries = summaries .iter() .filter(|&(summary, yanked)| { - !yanked || yanked_whitelist.contains(&summary.package_id()) + !yanked || { + log::debug!("{:?}", yanked_whitelist); + log::debug!("{:?}", summary.package_id()); + yanked_whitelist.contains(&summary.package_id()) + } }) .map(|s| s.0.clone()); diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 7ee105a9aea..33479dde648 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -625,4 +625,8 @@ impl<'cfg> Source for RegistrySource<'cfg> { fn describe(&self) -> String { self.source_id.display_registry() } + + fn add_to_yanked_whitelist(&mut self, pkgs: &[PackageId]) { + self.yanked_whitelist.extend(pkgs); + } } diff --git a/src/cargo/sources/replaced.rs b/src/cargo/sources/replaced.rs index 4a4de90a419..465b0f08de4 100644 --- a/src/cargo/sources/replaced.rs +++ b/src/cargo/sources/replaced.rs @@ -113,4 +113,10 @@ impl<'cfg> Source for ReplacedSource<'cfg> { fn is_replaced(&self) -> bool { true } + + fn add_to_yanked_whitelist(&mut self, pkgs: &[PackageId]) { + let pkgs = pkgs.iter().map(|id| id.with_source_id(self.replace_with)) + .collect::>(); + self.inner.add_to_yanked_whitelist(&pkgs); + } }