Skip to content

Commit cc0c97b

Browse files
FranciscoTGouveiarami3l
authored andcommitted
fix(installation): extract installation of a component into a separate function
1 parent 552e50b commit cc0c97b

File tree

1 file changed

+54
-37
lines changed

1 file changed

+54
-37
lines changed

src/dist/manifestation.rs

Lines changed: 54 additions & 37 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,14 @@ 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 = self.install_component(
261+
component_bin,
262+
installer_file,
263+
download_cfg,
264+
new_manifest,
265+
tx,
266+
)?;
294267
}
295268

296269
// Install new distribution manifest
@@ -305,7 +278,7 @@ impl Manifestation {
305278
// `Components` *also* tracks what is installed, but it only tracks names, not
306279
// name/target. Needs to be fixed in rust-installer.
307280
let new_config = Config {
308-
components: update.final_component_list,
281+
components: update.final_component_list.clone(),
309282
..Config::default()
310283
};
311284
let config_str = new_config.stringify()?;
@@ -499,6 +472,50 @@ impl Manifestation {
499472

500473
Ok(tx)
501474
}
475+
476+
fn install_component<'a>(
477+
&self,
478+
component_bin: ComponentBinary<'a>,
479+
installer_file: File,
480+
download_cfg: &DownloadCfg<'_>,
481+
new_manifest: &Manifest,
482+
tx: Transaction<'a>,
483+
) -> Result<Transaction<'a>> {
484+
// For historical reasons, the rust-installer component
485+
// names are not the same as the dist manifest component
486+
// names. Some are just the component name some are the
487+
// component name plus the target triple.
488+
let pkg_name = component_bin.component.name_in_manifest();
489+
let short_pkg_name = component_bin.component.short_name_in_manifest();
490+
let short_name = component_bin.component.short_name(new_manifest);
491+
492+
match &component_bin.component.target {
493+
Some(t) if t != &self.target_triple => {
494+
info!("installing component {short_name}");
495+
}
496+
_ => {
497+
info!(
498+
"installing component {short_name} for target {}",
499+
self.target_triple
500+
)
501+
}
502+
}
503+
504+
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
505+
let package = match component_bin.binary.compression {
506+
CompressionKind::GZip => &TarGzPackage::new(reader, download_cfg)? as &dyn Package,
507+
CompressionKind::XZ => &TarXzPackage::new(reader, download_cfg)?,
508+
CompressionKind::ZStd => &TarZStdPackage::new(reader, download_cfg)?,
509+
};
510+
511+
// If the package doesn't contain the component that the
512+
// manifest says it does then somebody must be playing a joke on us.
513+
if !package.contains(&pkg_name, Some(short_pkg_name)) {
514+
return Err(RustupError::CorruptComponent(short_name).into());
515+
}
516+
517+
package.install(&self.installation, &pkg_name, Some(short_pkg_name), tx)
518+
}
502519
}
503520

504521
#[derive(Debug)]

0 commit comments

Comments
 (0)