Skip to content

Commit 09df8be

Browse files
FranciscoTGouveiarami3l
authored andcommitted
refactor(installation): extract installation of a component into a separate function
Co-authored-by: rami3l <rami3l@outlook.com>
1 parent 7d03db9 commit 09df8be

File tree

1 file changed

+53
-36
lines changed

1 file changed

+53
-36
lines changed

src/dist/manifestation.rs

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl Manifestation {
213213
for result in results {
214214
let (bin, downloaded_file) = result?;
215215
things_downloaded.push(bin.binary.hash.clone());
216-
things_to_install.push((bin.component, bin.binary.compression, downloaded_file));
216+
things_to_install.push((bin, downloaded_file));
217217
}
218218
}
219219

@@ -256,41 +256,8 @@ impl Manifestation {
256256
}
257257

258258
// Install components
259-
for (component, format, installer_file) in things_to_install {
260-
// For historical reasons, the rust-installer component
261-
// names are not the same as the dist manifest component
262-
// names. Some are just the component name some are the
263-
// component name plus the target triple.
264-
let pkg_name = component.name_in_manifest();
265-
let short_pkg_name = component.short_name_in_manifest();
266-
let short_name = component.short_name(new_manifest);
267-
268-
match &component.target {
269-
Some(t) if t != &self.target_triple => {
270-
info!("installing component {short_name}");
271-
}
272-
_ => {
273-
info!(
274-
"installing component {short_name} for target {}",
275-
self.target_triple
276-
)
277-
}
278-
}
279-
280-
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
281-
let package = match format {
282-
CompressionKind::GZip => &TarGzPackage::new(reader, download_cfg)? as &dyn Package,
283-
CompressionKind::XZ => &TarXzPackage::new(reader, download_cfg)?,
284-
CompressionKind::ZStd => &TarZStdPackage::new(reader, download_cfg)?,
285-
};
286-
287-
// If the package doesn't contain the component that the
288-
// manifest says it does then somebody must be playing a joke on us.
289-
if !package.contains(&pkg_name, Some(short_pkg_name)) {
290-
return Err(RustupError::CorruptComponent(short_name).into());
291-
}
292-
293-
tx = package.install(&self.installation, &pkg_name, Some(short_pkg_name), tx)?;
259+
for (component_bin, installer_file) in things_to_install {
260+
tx = component_bin.install(installer_file, tx, new_manifest, self, download_cfg)?;
294261
}
295262

296263
// Install new distribution manifest
@@ -759,4 +726,54 @@ impl<'a> ComponentBinary<'a> {
759726

760727
Ok(downloaded_file)
761728
}
729+
730+
fn install<'t>(
731+
&self,
732+
installer_file: File,
733+
tx: Transaction<'t>,
734+
new_manifest: &Manifest,
735+
manifestation: &Manifestation,
736+
download_cfg: &DownloadCfg<'_>,
737+
) -> Result<Transaction<'t>> {
738+
// For historical reasons, the rust-installer component
739+
// names are not the same as the dist manifest component
740+
// names. Some are just the component name some are the
741+
// component name plus the target triple.
742+
let component = self.component;
743+
let pkg_name = component.name_in_manifest();
744+
let short_pkg_name = component.short_name_in_manifest();
745+
let short_name = component.short_name(new_manifest);
746+
747+
match &component.target {
748+
Some(t) if t != &manifestation.target_triple => {
749+
info!("installing component {short_name}");
750+
}
751+
_ => {
752+
info!(
753+
"installing component {short_name} for target {}",
754+
manifestation.target_triple
755+
)
756+
}
757+
}
758+
759+
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
760+
let package = match self.binary.compression {
761+
CompressionKind::GZip => &TarGzPackage::new(reader, download_cfg)? as &dyn Package,
762+
CompressionKind::XZ => &TarXzPackage::new(reader, download_cfg)?,
763+
CompressionKind::ZStd => &TarZStdPackage::new(reader, download_cfg)?,
764+
};
765+
766+
// If the package doesn't contain the component that the
767+
// manifest says it does then somebody must be playing a joke on us.
768+
if !package.contains(&pkg_name, Some(short_pkg_name)) {
769+
return Err(RustupError::CorruptComponent(short_name).into());
770+
}
771+
772+
package.install(
773+
&manifestation.installation,
774+
&pkg_name,
775+
Some(short_pkg_name),
776+
tx,
777+
)
778+
}
762779
}

0 commit comments

Comments
 (0)