Skip to content

Commit 9182627

Browse files
committed
dist: reuse existing DownloadCfg in update_v1()
1 parent 9f58ba2 commit 9182627

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

src/dist/manifestation.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::dist::config::Config;
2020
use crate::dist::download::{DownloadCfg, File};
2121
use crate::dist::manifest::{Component, CompressionKind, HashedBinary, Manifest, TargetedPackage};
2222
use crate::dist::prefix::InstallPrefix;
23+
#[cfg(test)]
2324
use crate::dist::temp;
2425
use crate::dist::{DEFAULT_DIST_SERVER, Profile, TargetTriple};
2526
use crate::errors::RustupError;
@@ -428,9 +429,7 @@ impl Manifestation {
428429
&self,
429430
new_manifest: &[String],
430431
update_hash: Option<&Path>,
431-
tmp_cx: &temp::Context,
432-
notify_handler: &dyn Fn(Notification<'_>),
433-
process: &Process,
432+
dl_cfg: &DownloadCfg<'_>,
434433
) -> Result<Option<String>> {
435434
// If there's already a v2 installation then something has gone wrong
436435
if self.read_config()?.is_some() {
@@ -451,25 +450,16 @@ impl Manifestation {
451450
// Only replace once. The cost is inexpensive.
452451
let url = url
453452
.unwrap()
454-
.replace(DEFAULT_DIST_SERVER, tmp_cx.dist_server.as_str());
453+
.replace(DEFAULT_DIST_SERVER, dl_cfg.tmp_cx.dist_server.as_str());
455454

456-
notify_handler(Notification::DownloadingComponent(
455+
(dl_cfg.notify_handler)(Notification::DownloadingComponent(
457456
"rust",
458457
&self.target_triple,
459458
Some(&self.target_triple),
460459
&url,
461460
));
462461

463-
use std::path::PathBuf;
464-
let dld_dir = PathBuf::from("bogus");
465-
let dlcfg = DownloadCfg {
466-
download_dir: &dld_dir,
467-
tmp_cx,
468-
notify_handler,
469-
process,
470-
};
471-
472-
let dl = dlcfg
462+
let dl = dl_cfg
473463
.download_and_check(&url, update_hash, ".tar.gz")
474464
.await?;
475465
if dl.is_none() {
@@ -481,20 +471,21 @@ impl Manifestation {
481471
info!("installing component rust");
482472

483473
// Begin transaction
484-
let mut tx = Transaction::new(prefix, tmp_cx, process);
474+
let mut tx = Transaction::new(prefix, dl_cfg.tmp_cx, dl_cfg.process);
485475

486476
// Uninstall components
487477
let components = self.installation.list()?;
488478
for component in components {
489-
tx = component.uninstall(tx, process)?;
479+
tx = component.uninstall(tx, dl_cfg.process)?;
490480
}
491481

492482
// Install all the components in the installer
493-
let reader = utils::FileReaderWithProgress::new_file(&installer_file, notify_handler)?;
483+
let reader =
484+
utils::FileReaderWithProgress::new_file(&installer_file, dl_cfg.notify_handler)?;
494485
let cx = PackageContext {
495-
tmp_cx,
496-
notify_handler: Some(notify_handler),
497-
process,
486+
tmp_cx: dl_cfg.tmp_cx,
487+
notify_handler: Some(dl_cfg.notify_handler),
488+
process: dl_cfg.process,
498489
};
499490

500491
let package: &dyn Package = &TarGzPackage::new(reader, &cx)?;

src/dist/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,9 +1216,7 @@ async fn try_update_from_dist_(
12161216
.update_v1(
12171217
&manifest,
12181218
update_hash,
1219-
download.tmp_cx,
1220-
&download.notify_handler,
1221-
download.process,
1219+
download,
12221220
)
12231221
.await;
12241222

0 commit comments

Comments
 (0)