Skip to content

Commit

Permalink
Auto merge of #6842 - alexcrichton:set-cksum, r=ehuss
Browse files Browse the repository at this point in the history
Ensure Summary::checksum works for registry crates

While not actually used in Cargo itself the `Summary::checksum` method
of downloaded packages from the registry currently returns `None`. This
was accidentally regressed in #6500 and noticed when updating
`cargo-vendor` (it took a long time to get around to updating that).

The fix here is to override the `checksum` field of the summary for
packages we return from the registry, and everything else should remain
the same!
  • Loading branch information
bors committed Apr 13, 2019
2 parents 43fc23c + 014ef2e commit 2510c0c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ impl Manifest {
pub fn summary(&self) -> &Summary {
&self.summary
}
pub fn summary_mut(&mut self) -> &mut Summary {
&mut self.summary
}
pub fn targets(&self) -> &[Target] {
&self.targets
}
Expand Down Expand Up @@ -470,10 +473,6 @@ impl Manifest {
&self.features
}

pub fn set_summary(&mut self, summary: Summary) {
self.summary = summary;
}

pub fn map_source(self, to_replace: SourceId, replace_with: SourceId) -> Manifest {
Manifest {
summary: self.summary.map_source(to_replace, replace_with),
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ impl Package {
pub fn manifest(&self) -> &Manifest {
&self.manifest
}
/// Gets the manifest.
pub fn manifest_mut(&mut self) -> &mut Manifest {
&mut self.manifest
}
/// Gets the path to the manifest.
pub fn manifest_path(&self) -> &Path {
&self.manifest_path
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/core/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ impl Summary {
self
}

pub fn set_checksum(mut self, cksum: String) -> Summary {
pub fn set_checksum(&mut self, cksum: String) {
Rc::make_mut(&mut self.inner).checksum = Some(cksum);
self
}

pub fn map_dependencies<F>(mut self, f: F) -> Summary
Expand Down
12 changes: 5 additions & 7 deletions src/cargo/sources/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {

let mut src = PathSource::new(&path, self.source_id, self.config);
src.update()?;
let pkg = src.root_package()?;
let mut pkg = src.root_package()?;

let cksum_file = path.join(".cargo-checksum.json");
let cksum = paths::read(&path.join(cksum_file)).chain_err(|| {
Expand All @@ -136,13 +136,11 @@ impl<'cfg> Source for DirectorySource<'cfg> {
)
})?;

let mut manifest = pkg.manifest().clone();
let mut summary = manifest.summary().clone();
if let Some(ref package) = cksum.package {
summary = summary.set_checksum(package.clone());
if let Some(package) = &cksum.package {
pkg.manifest_mut()
.summary_mut()
.set_checksum(package.clone());
}
manifest.set_summary(summary);
let pkg = Package::new(manifest, pkg.manifest_path());
self.packages.insert(pkg.package_id(), (pkg, cksum));
}

Expand Down
4 changes: 2 additions & 2 deletions src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ impl<'cfg> RegistryIndex<'cfg> {
.into_iter()
.map(|dep| dep.into_dep(self.source_id))
.collect::<CargoResult<Vec<_>>>()?;
let summary = Summary::new(pkgid, deps, &features, links, false)?;
let summary = summary.set_checksum(cksum.clone());
let mut summary = Summary::new(pkgid, deps, &features, links, false)?;
summary.set_checksum(cksum.clone());
self.hashes
.entry(name.as_str())
.or_insert_with(HashMap::new)
Expand Down
19 changes: 18 additions & 1 deletion src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,27 @@ impl<'cfg> RegistrySource<'cfg> {
.chain_err(|| internal(format!("failed to unpack package `{}`", package)))?;
let mut src = PathSource::new(&path, self.source_id, self.config);
src.update()?;
let pkg = match src.download(package)? {
let mut pkg = match src.download(package)? {
MaybePackage::Ready(pkg) => pkg,
MaybePackage::Download { .. } => unreachable!(),
};

// After we've loaded the package configure it's summary's `checksum`
// field with the checksum we know for this `PackageId`.
let summaries = self
.index
.summaries(package.name().as_str(), &mut *self.ops)?;
let summary_with_cksum = summaries
.iter()
.map(|s| &s.0)
.find(|s| s.package_id() == package)
.expect("summary not found");
if let Some(cksum) = summary_with_cksum.checksum() {
pkg.manifest_mut()
.summary_mut()
.set_checksum(cksum.to_string());
}

Ok(pkg)
}
}
Expand Down

0 comments on commit 2510c0c

Please sign in to comment.