Skip to content

Commit 2510c0c

Browse files
committed
Auto merge of #6842 - alexcrichton:set-cksum, r=ehuss
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!
2 parents 43fc23c + 014ef2e commit 2510c0c

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

src/cargo/core/manifest.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ impl Manifest {
428428
pub fn summary(&self) -> &Summary {
429429
&self.summary
430430
}
431+
pub fn summary_mut(&mut self) -> &mut Summary {
432+
&mut self.summary
433+
}
431434
pub fn targets(&self) -> &[Target] {
432435
&self.targets
433436
}
@@ -470,10 +473,6 @@ impl Manifest {
470473
&self.features
471474
}
472475

473-
pub fn set_summary(&mut self, summary: Summary) {
474-
self.summary = summary;
475-
}
476-
477476
pub fn map_source(self, to_replace: SourceId, replace_with: SourceId) -> Manifest {
478477
Manifest {
479478
summary: self.summary.map_source(to_replace, replace_with),

src/cargo/core/package.rs

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ impl Package {
146146
pub fn manifest(&self) -> &Manifest {
147147
&self.manifest
148148
}
149+
/// Gets the manifest.
150+
pub fn manifest_mut(&mut self) -> &mut Manifest {
151+
&mut self.manifest
152+
}
149153
/// Gets the path to the manifest.
150154
pub fn manifest_path(&self) -> &Path {
151155
&self.manifest_path

src/cargo/core/summary.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ impl Summary {
104104
self
105105
}
106106

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

112111
pub fn map_dependencies<F>(mut self, f: F) -> Summary

src/cargo/sources/directory.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {
116116

117117
let mut src = PathSource::new(&path, self.source_id, self.config);
118118
src.update()?;
119-
let pkg = src.root_package()?;
119+
let mut pkg = src.root_package()?;
120120

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

139-
let mut manifest = pkg.manifest().clone();
140-
let mut summary = manifest.summary().clone();
141-
if let Some(ref package) = cksum.package {
142-
summary = summary.set_checksum(package.clone());
139+
if let Some(package) = &cksum.package {
140+
pkg.manifest_mut()
141+
.summary_mut()
142+
.set_checksum(package.clone());
143143
}
144-
manifest.set_summary(summary);
145-
let pkg = Package::new(manifest, pkg.manifest_path());
146144
self.packages.insert(pkg.package_id(), (pkg, cksum));
147145
}
148146

src/cargo/sources/registry/index.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ impl<'cfg> RegistryIndex<'cfg> {
253253
.into_iter()
254254
.map(|dep| dep.into_dep(self.source_id))
255255
.collect::<CargoResult<Vec<_>>>()?;
256-
let summary = Summary::new(pkgid, deps, &features, links, false)?;
257-
let summary = summary.set_checksum(cksum.clone());
256+
let mut summary = Summary::new(pkgid, deps, &features, links, false)?;
257+
summary.set_checksum(cksum.clone());
258258
self.hashes
259259
.entry(name.as_str())
260260
.or_insert_with(HashMap::new)

src/cargo/sources/registry/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,27 @@ impl<'cfg> RegistrySource<'cfg> {
534534
.chain_err(|| internal(format!("failed to unpack package `{}`", package)))?;
535535
let mut src = PathSource::new(&path, self.source_id, self.config);
536536
src.update()?;
537-
let pkg = match src.download(package)? {
537+
let mut pkg = match src.download(package)? {
538538
MaybePackage::Ready(pkg) => pkg,
539539
MaybePackage::Download { .. } => unreachable!(),
540540
};
541+
542+
// After we've loaded the package configure it's summary's `checksum`
543+
// field with the checksum we know for this `PackageId`.
544+
let summaries = self
545+
.index
546+
.summaries(package.name().as_str(), &mut *self.ops)?;
547+
let summary_with_cksum = summaries
548+
.iter()
549+
.map(|s| &s.0)
550+
.find(|s| s.package_id() == package)
551+
.expect("summary not found");
552+
if let Some(cksum) = summary_with_cksum.checksum() {
553+
pkg.manifest_mut()
554+
.summary_mut()
555+
.set_checksum(cksum.to_string());
556+
}
557+
541558
Ok(pkg)
542559
}
543560
}

0 commit comments

Comments
 (0)