Skip to content

Commit

Permalink
Update existing sources when whitelist modified
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Feb 3, 2019
1 parent 086a454 commit 4a2f810
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/cargo/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ impl<'cfg> PackageRegistry<'cfg> {
}

pub fn add_to_yanked_whitelist(&mut self, iter: impl Iterator<Item = PackageId>) {
self.yanked_whitelist.extend(iter)
let pkgs = iter.collect::<Vec<_>>();
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<PackageId>) {
Expand Down
13 changes: 13 additions & 0 deletions src/cargo/core/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -152,6 +157,10 @@ impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
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 {
Expand Down Expand Up @@ -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<Source>`
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/sources/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {}
}
2 changes: 2 additions & 0 deletions src/cargo/sources/git/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {}
}
6 changes: 5 additions & 1 deletion src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
4 changes: 4 additions & 0 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/cargo/sources/replaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
self.inner.add_to_yanked_whitelist(&pkgs);
}
}

0 comments on commit 4a2f810

Please sign in to comment.