Skip to content

Commit 2fa788a

Browse files
authored
Merge pull request #3449 from rbtcollins/refactor-update
Refactor: Use download_cfg.notify_handler in update()
2 parents 4b6bbc3 + 6e54dcc commit 2fa788a

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

src/dist/dist.rs

-1
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,6 @@ fn try_update_from_dist_(
927927
changes,
928928
force_update,
929929
&download,
930-
&download.notify_handler,
931930
&toolchain.manifest_name(),
932931
true,
933932
) {

src/dist/manifestation.rs

+25-14
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ impl Manifestation {
106106
changes: Changes,
107107
force_update: bool,
108108
download_cfg: &DownloadCfg<'_>,
109-
notify_handler: &dyn Fn(Notification<'_>),
110109
toolchain_str: &str,
111110
implicit_modify: bool,
112111
) -> Result<UpdateStatus> {
@@ -118,8 +117,13 @@ impl Manifestation {
118117

119118
// Create the lists of components needed for installation
120119
let config = self.read_config()?;
121-
let mut update =
122-
Update::build_update(self, new_manifest, &changes, &config, notify_handler)?;
120+
let mut update = Update::build_update(
121+
self,
122+
new_manifest,
123+
&changes,
124+
&config,
125+
&download_cfg.notify_handler,
126+
)?;
123127

124128
if update.nothing_changes() {
125129
return Ok(UpdateStatus::Unchanged);
@@ -134,9 +138,11 @@ impl Manifestation {
134138
e.downcast::<RustupError>()
135139
{
136140
for component in &components {
137-
notify_handler(Notification::ForcingUnavailableComponent(
138-
component.name(new_manifest).as_str(),
139-
));
141+
(download_cfg.notify_handler)(
142+
Notification::ForcingUnavailableComponent(
143+
component.name(new_manifest).as_str(),
144+
),
145+
);
140146
}
141147
update.drop_components_to_install(&components);
142148
}
@@ -161,7 +167,7 @@ impl Manifestation {
161167
.unwrap_or(DEFAULT_MAX_RETRIES);
162168

163169
for (component, format, url, hash) in components {
164-
notify_handler(Notification::DownloadingComponent(
170+
(download_cfg.notify_handler)(Notification::DownloadingComponent(
165171
&component.short_name(new_manifest),
166172
&self.target_triple,
167173
component.target.as_ref(),
@@ -180,11 +186,11 @@ impl Manifestation {
180186
Err(e) => {
181187
match e.downcast_ref::<RustupError>() {
182188
Some(RustupError::BrokenPartialFile) => {
183-
notify_handler(Notification::RetryingDownload(&url));
189+
(download_cfg.notify_handler)(Notification::RetryingDownload(&url));
184190
return OperationResult::Retry(OperationError(e));
185191
}
186192
Some(RustupError::DownloadingFile { .. }) => {
187-
notify_handler(Notification::RetryingDownload(&url));
193+
(download_cfg.notify_handler)(Notification::RetryingDownload(&url));
188194
return OperationResult::Retry(OperationError(e));
189195
}
190196
Some(_) => return OperationResult::Err(OperationError(e)),
@@ -202,7 +208,7 @@ impl Manifestation {
202208
}
203209

204210
// Begin transaction
205-
let mut tx = Transaction::new(prefix.clone(), temp_cfg, notify_handler);
211+
let mut tx = Transaction::new(prefix.clone(), temp_cfg, download_cfg.notify_handler);
206212

207213
// If the previous installation was from a v1 manifest we need
208214
// to uninstall it first.
@@ -215,13 +221,18 @@ impl Manifestation {
215221
} else {
216222
Notification::RemovingComponent
217223
};
218-
notify_handler(notification(
224+
(download_cfg.notify_handler)(notification(
219225
&component.short_name(new_manifest),
220226
&self.target_triple,
221227
component.target.as_ref(),
222228
));
223229

224-
tx = self.uninstall_component(component, new_manifest, tx, &notify_handler)?;
230+
tx = self.uninstall_component(
231+
component,
232+
new_manifest,
233+
tx,
234+
&download_cfg.notify_handler,
235+
)?;
225236
}
226237

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

237-
notify_handler(Notification::InstallingComponent(
248+
(download_cfg.notify_handler)(Notification::InstallingComponent(
238249
&short_name,
239250
&self.target_triple,
240251
component.target.as_ref(),
241252
));
242253

243254
let notification_converter = |notification: crate::utils::Notification<'_>| {
244-
notify_handler(notification.into());
255+
(download_cfg.notify_handler)(notification.into());
245256
};
246257
let gz;
247258
let xz;

src/dist/manifestation/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ fn update_from_dist(
466466
changes,
467467
force,
468468
download_cfg,
469-
download_cfg.notify_handler,
470469
&toolchain.manifest_name(),
471470
true,
472471
)

src/toolchain/distributable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ impl<'a> DistributableToolchain<'a> {
108108
changes,
109109
false,
110110
&download_cfg,
111-
&download_cfg.notify_handler,
112111
&self.desc.manifest_name(),
113112
false,
114113
)?;
@@ -500,7 +499,6 @@ impl<'a> DistributableToolchain<'a> {
500499
changes,
501500
false,
502501
&download_cfg,
503-
&download_cfg.notify_handler,
504502
&self.desc.manifest_name(),
505503
false,
506504
)?;

0 commit comments

Comments
 (0)