Skip to content

Commit 3154bf1

Browse files
fix(installation): extract installation of a component into a separate function
1 parent 640a19b commit 3154bf1

File tree

1 file changed

+80
-59
lines changed

1 file changed

+80
-59
lines changed

src/dist/manifestation.rs

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -250,65 +250,15 @@ impl Manifestation {
250250

251251
// Install components
252252
for (component, format, installer_file) in things_to_install {
253-
// For historical reasons, the rust-installer component
254-
// names are not the same as the dist manifest component
255-
// names. Some are just the component name some are the
256-
// component name plus the target triple.
257-
let pkg_name = component.name_in_manifest();
258-
let short_pkg_name = component.short_name_in_manifest();
259-
let short_name = component.short_name(new_manifest);
260-
261-
(download_cfg.notify_handler)(Notification::InstallingComponent(
262-
&short_name,
263-
&self.target_triple,
264-
component.target.as_ref(),
265-
));
266-
267-
let notification_converter = |notification: crate::utils::Notification<'_>| {
268-
(download_cfg.notify_handler)(notification.into());
269-
};
270-
let gz;
271-
let xz;
272-
let zst;
273-
let reader =
274-
utils::FileReaderWithProgress::new_file(&installer_file, &notification_converter)?;
275-
let package: &dyn Package = match format {
276-
CompressionKind::GZip => {
277-
gz = TarGzPackage::new(
278-
reader,
279-
tmp_cx,
280-
Some(&notification_converter),
281-
download_cfg.process,
282-
)?;
283-
&gz
284-
}
285-
CompressionKind::XZ => {
286-
xz = TarXzPackage::new(
287-
reader,
288-
tmp_cx,
289-
Some(&notification_converter),
290-
download_cfg.process,
291-
)?;
292-
&xz
293-
}
294-
CompressionKind::ZStd => {
295-
zst = TarZStdPackage::new(
296-
reader,
297-
tmp_cx,
298-
Some(&notification_converter),
299-
download_cfg.process,
300-
)?;
301-
&zst
302-
}
303-
};
304-
305-
// If the package doesn't contain the component that the
306-
// manifest says it does then somebody must be playing a joke on us.
307-
if !package.contains(&pkg_name, Some(short_pkg_name)) {
308-
return Err(RustupError::CorruptComponent(short_name).into());
309-
}
310-
311-
tx = package.install(&self.installation, &pkg_name, Some(short_pkg_name), tx)?;
253+
tx = self.install_component(
254+
component,
255+
format,
256+
installer_file,
257+
tmp_cx,
258+
download_cfg,
259+
new_manifest,
260+
tx,
261+
)?;
312262
}
313263

314264
// Install new distribution manifest
@@ -591,6 +541,77 @@ impl Manifestation {
591541

592542
Ok((component, format, downloaded_file, hash))
593543
}
544+
545+
fn install_component<'a>(
546+
&self,
547+
component: Component,
548+
format: CompressionKind,
549+
installer_file: File,
550+
tmp_cx: &temp::Context,
551+
download_cfg: &DownloadCfg<'_>,
552+
new_manifest: &Manifest,
553+
tx: Transaction<'a>,
554+
) -> Result<Transaction<'a>> {
555+
// For historical reasons, the rust-installer component
556+
// names are not the same as the dist manifest component
557+
// names. Some are just the component name some are the
558+
// component name plus the target triple.
559+
let pkg_name = component.name_in_manifest();
560+
let short_pkg_name = component.short_name_in_manifest();
561+
let short_name = component.short_name(new_manifest);
562+
563+
(download_cfg.notify_handler)(Notification::InstallingComponent(
564+
&short_name,
565+
&self.target_triple,
566+
component.target.as_ref(),
567+
));
568+
569+
let notification_converter = |notification: crate::utils::Notification<'_>| {
570+
(download_cfg.notify_handler)(notification.into());
571+
};
572+
let gz;
573+
let xz;
574+
let zst;
575+
let reader =
576+
utils::FileReaderWithProgress::new_file(&installer_file, &notification_converter)?;
577+
let package: &dyn Package = match format {
578+
CompressionKind::GZip => {
579+
gz = TarGzPackage::new(
580+
reader,
581+
tmp_cx,
582+
Some(&notification_converter),
583+
download_cfg.process,
584+
)?;
585+
&gz
586+
}
587+
CompressionKind::XZ => {
588+
xz = TarXzPackage::new(
589+
reader,
590+
tmp_cx,
591+
Some(&notification_converter),
592+
download_cfg.process,
593+
)?;
594+
&xz
595+
}
596+
CompressionKind::ZStd => {
597+
zst = TarZStdPackage::new(
598+
reader,
599+
tmp_cx,
600+
Some(&notification_converter),
601+
download_cfg.process,
602+
)?;
603+
&zst
604+
}
605+
};
606+
607+
// If the package doesn't contain the component that the
608+
// manifest says it does then somebody must be playing a joke on us.
609+
if !package.contains(&pkg_name, Some(short_pkg_name)) {
610+
return Err(RustupError::CorruptComponent(short_name).into());
611+
}
612+
613+
package.install(&self.installation, &pkg_name, Some(short_pkg_name), tx)
614+
}
594615
}
595616

596617
#[derive(Debug)]

0 commit comments

Comments
 (0)