Skip to content

Commit 9051b19

Browse files
committed
dist: store more context in ComponentBinary
1 parent 0af53d4 commit 9051b19

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/dist/manifestation.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ impl Manifestation {
162162
component,
163163
binary,
164164
status: download_cfg.status_for(component.short_name(new_manifest)),
165+
manifest: new_manifest,
166+
download_cfg,
165167
})
166168
})
167169
.collect::<Result<Vec<_>>>()?;
@@ -187,7 +189,7 @@ impl Manifestation {
187189
let sem = semaphore.clone();
188190
async move {
189191
let _permit = sem.acquire().await.unwrap();
190-
bin.download(download_cfg, max_retries, new_manifest).await
192+
bin.download(max_retries).await
191193
}
192194
});
193195
if components_len > 0 {
@@ -242,7 +244,7 @@ impl Manifestation {
242244

243245
// Install components
244246
for (component_bin, installer_file) in things_to_install {
245-
tx = component_bin.install(installer_file, tx, new_manifest, self, download_cfg)?;
247+
tx = component_bin.install(installer_file, tx, self)?;
246248
}
247249

248250
// Install new distribution manifest
@@ -679,21 +681,21 @@ struct ComponentBinary<'a> {
679681
component: &'a Component,
680682
binary: &'a HashedBinary,
681683
status: DownloadStatus,
684+
manifest: &'a Manifest,
685+
download_cfg: &'a DownloadCfg<'a>,
682686
}
683687

684688
impl<'a> ComponentBinary<'a> {
685-
async fn download(
686-
self,
687-
download_cfg: &DownloadCfg<'_>,
688-
max_retries: usize,
689-
new_manifest: &Manifest,
690-
) -> Result<(Self, File)> {
689+
async fn download(self, max_retries: usize) -> Result<(Self, File)> {
691690
use tokio_retry::{RetryIf, strategy::FixedInterval};
692691

693-
let url = download_cfg.url(&self.binary.url)?;
692+
let url = self.download_cfg.url(&self.binary.url)?;
694693
let downloaded_file = RetryIf::spawn(
695694
FixedInterval::from_millis(0).take(max_retries),
696-
|| download_cfg.download(&url, &self.binary.hash, &self.status),
695+
|| {
696+
self.download_cfg
697+
.download(&url, &self.binary.hash, &self.status)
698+
},
697699
|e: &anyhow::Error| {
698700
// retry only known retriable cases
699701
match e.downcast_ref::<RustupError>() {
@@ -707,7 +709,9 @@ impl<'a> ComponentBinary<'a> {
707709
},
708710
)
709711
.await
710-
.with_context(|| RustupError::ComponentDownloadFailed(self.component.name(new_manifest)))?;
712+
.with_context(|| {
713+
RustupError::ComponentDownloadFailed(self.component.name(self.manifest))
714+
})?;
711715

712716
Ok((self, downloaded_file))
713717
}
@@ -716,9 +720,7 @@ impl<'a> ComponentBinary<'a> {
716720
&self,
717721
installer_file: File,
718722
tx: Transaction<'t>,
719-
new_manifest: &Manifest,
720723
manifestation: &Manifestation,
721-
download_cfg: &DownloadCfg<'_>,
722724
) -> Result<Transaction<'t>> {
723725
// For historical reasons, the rust-installer component
724726
// names are not the same as the dist manifest component
@@ -727,15 +729,15 @@ impl<'a> ComponentBinary<'a> {
727729
let component = self.component;
728730
let pkg_name = component.name_in_manifest();
729731
let short_pkg_name = component.short_name_in_manifest();
730-
let short_name = component.short_name(new_manifest);
732+
let short_name = component.short_name(self.manifest);
731733

732734
self.status.installing();
733735

734736
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
735737
let package = match self.binary.compression {
736-
CompressionKind::GZip => &TarGzPackage::new(reader, download_cfg)? as &dyn Package,
737-
CompressionKind::XZ => &TarXzPackage::new(reader, download_cfg)?,
738-
CompressionKind::ZStd => &TarZStdPackage::new(reader, download_cfg)?,
738+
CompressionKind::GZip => &TarGzPackage::new(reader, self.download_cfg)? as &dyn Package,
739+
CompressionKind::XZ => &TarXzPackage::new(reader, self.download_cfg)?,
740+
CompressionKind::ZStd => &TarZStdPackage::new(reader, self.download_cfg)?,
739741
};
740742

741743
// If the package doesn't contain the component that the

0 commit comments

Comments
 (0)