Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Summary::checksum works for registry crates #6842

Merged
merged 1 commit into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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