Skip to content

Commit

Permalink
Merge pull request #3449 from rbtcollins/refactor-update
Browse files Browse the repository at this point in the history
Refactor: Use download_cfg.notify_handler in update()
  • Loading branch information
rbtcollins authored Aug 19, 2023
2 parents 4b6bbc3 + 6e54dcc commit 2fa788a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,6 @@ fn try_update_from_dist_(
changes,
force_update,
&download,
&download.notify_handler,
&toolchain.manifest_name(),
true,
) {
Expand Down
39 changes: 25 additions & 14 deletions src/dist/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl Manifestation {
changes: Changes,
force_update: bool,
download_cfg: &DownloadCfg<'_>,
notify_handler: &dyn Fn(Notification<'_>),
toolchain_str: &str,
implicit_modify: bool,
) -> Result<UpdateStatus> {
Expand All @@ -118,8 +117,13 @@ impl Manifestation {

// Create the lists of components needed for installation
let config = self.read_config()?;
let mut update =
Update::build_update(self, new_manifest, &changes, &config, notify_handler)?;
let mut update = Update::build_update(
self,
new_manifest,
&changes,
&config,
&download_cfg.notify_handler,
)?;

if update.nothing_changes() {
return Ok(UpdateStatus::Unchanged);
Expand All @@ -134,9 +138,11 @@ impl Manifestation {
e.downcast::<RustupError>()
{
for component in &components {
notify_handler(Notification::ForcingUnavailableComponent(
component.name(new_manifest).as_str(),
));
(download_cfg.notify_handler)(
Notification::ForcingUnavailableComponent(
component.name(new_manifest).as_str(),
),
);
}
update.drop_components_to_install(&components);
}
Expand All @@ -161,7 +167,7 @@ impl Manifestation {
.unwrap_or(DEFAULT_MAX_RETRIES);

for (component, format, url, hash) in components {
notify_handler(Notification::DownloadingComponent(
(download_cfg.notify_handler)(Notification::DownloadingComponent(
&component.short_name(new_manifest),
&self.target_triple,
component.target.as_ref(),
Expand All @@ -180,11 +186,11 @@ impl Manifestation {
Err(e) => {
match e.downcast_ref::<RustupError>() {
Some(RustupError::BrokenPartialFile) => {
notify_handler(Notification::RetryingDownload(&url));
(download_cfg.notify_handler)(Notification::RetryingDownload(&url));
return OperationResult::Retry(OperationError(e));
}
Some(RustupError::DownloadingFile { .. }) => {
notify_handler(Notification::RetryingDownload(&url));
(download_cfg.notify_handler)(Notification::RetryingDownload(&url));
return OperationResult::Retry(OperationError(e));
}
Some(_) => return OperationResult::Err(OperationError(e)),
Expand All @@ -202,7 +208,7 @@ impl Manifestation {
}

// Begin transaction
let mut tx = Transaction::new(prefix.clone(), temp_cfg, notify_handler);
let mut tx = Transaction::new(prefix.clone(), temp_cfg, download_cfg.notify_handler);

// If the previous installation was from a v1 manifest we need
// to uninstall it first.
Expand All @@ -215,13 +221,18 @@ impl Manifestation {
} else {
Notification::RemovingComponent
};
notify_handler(notification(
(download_cfg.notify_handler)(notification(
&component.short_name(new_manifest),
&self.target_triple,
component.target.as_ref(),
));

tx = self.uninstall_component(component, new_manifest, tx, &notify_handler)?;
tx = self.uninstall_component(
component,
new_manifest,
tx,
&download_cfg.notify_handler,
)?;
}

// Install components
Expand All @@ -234,14 +245,14 @@ impl Manifestation {
let short_pkg_name = component.short_name_in_manifest();
let short_name = component.short_name(new_manifest);

notify_handler(Notification::InstallingComponent(
(download_cfg.notify_handler)(Notification::InstallingComponent(
&short_name,
&self.target_triple,
component.target.as_ref(),
));

let notification_converter = |notification: crate::utils::Notification<'_>| {
notify_handler(notification.into());
(download_cfg.notify_handler)(notification.into());
};
let gz;
let xz;
Expand Down
1 change: 0 additions & 1 deletion src/dist/manifestation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ fn update_from_dist(
changes,
force,
download_cfg,
download_cfg.notify_handler,
&toolchain.manifest_name(),
true,
)
Expand Down
2 changes: 0 additions & 2 deletions src/toolchain/distributable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ impl<'a> DistributableToolchain<'a> {
changes,
false,
&download_cfg,
&download_cfg.notify_handler,
&self.desc.manifest_name(),
false,
)?;
Expand Down Expand Up @@ -500,7 +499,6 @@ impl<'a> DistributableToolchain<'a> {
changes,
false,
&download_cfg,
&download_cfg.notify_handler,
&self.desc.manifest_name(),
false,
)?;
Expand Down

0 comments on commit 2fa788a

Please sign in to comment.