Skip to content

Commit ad0330f

Browse files
committed
download: extract DownloadCfg initialization from Cfg
1 parent 9b07e56 commit ad0330f

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

src/config.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ use tracing::{debug, error, info, trace, warn};
1313
use crate::dist::AutoInstallMode;
1414
use crate::{
1515
cli::{common, self_update::SelfUpdateMode},
16-
dist::{
17-
self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc, download::DownloadCfg,
18-
temp,
19-
},
16+
dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc, temp},
2017
errors::RustupError,
2118
fallback_settings::FallbackSettings,
2219
install::UpdateStatus,
@@ -321,17 +318,6 @@ impl<'a> Cfg<'a> {
321318
Ok(cfg)
322319
}
323320

324-
/// construct a download configuration
325-
pub(crate) fn download_cfg(&'a self) -> DownloadCfg<'a> {
326-
DownloadCfg {
327-
dist_root: &self.dist_root_url,
328-
tmp_cx: &self.tmp_cx,
329-
download_dir: &self.download_dir,
330-
notify_handler: &*self.notify_handler,
331-
process: self.process,
332-
}
333-
}
334-
335321
pub(crate) fn set_profile_override(&mut self, profile: Profile) {
336322
self.profile_override = Some(profile);
337323
}

src/dist/download.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use tracing::debug;
88
use tracing::warn;
99
use url::Url;
1010

11+
use crate::config::Cfg;
1112
use crate::dist::temp;
1213
use crate::download::download_file;
1314
use crate::download::download_file_with_resume;
@@ -40,6 +41,17 @@ impl ops::Deref for File {
4041
}
4142

4243
impl<'a> DownloadCfg<'a> {
44+
/// construct a download configuration
45+
pub(crate) fn new(cfg: &'a Cfg<'a>) -> Self {
46+
DownloadCfg {
47+
dist_root: &cfg.dist_root_url,
48+
tmp_cx: &cfg.tmp_cx,
49+
download_dir: &cfg.download_dir,
50+
notify_handler: &*cfg.notify_handler,
51+
process: cfg.process,
52+
}
53+
}
54+
4355
/// Downloads a file and validates its hash. Resumes interrupted downloads.
4456
/// Partial downloads are stored in `self.download_dir`, keyed by hash. If the
4557
/// target file already exists, then the hash is checked and it is returned

src/toolchain/distributable.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
dist::{
1414
DistOptions, PartialToolchainDesc, Profile, ToolchainDesc,
1515
config::Config,
16+
download::DownloadCfg,
1617
manifest::{Component, ComponentStatus, Manifest},
1718
manifestation::{Changes, Manifestation},
1819
prefix::InstallPrefix,
@@ -109,7 +110,7 @@ impl<'a> DistributableToolchain<'a> {
109110
remove_components: vec![],
110111
};
111112

112-
let download_cfg = self.toolchain.cfg.download_cfg();
113+
let download_cfg = DownloadCfg::new(self.toolchain.cfg);
113114
manifestation
114115
.update(
115116
&manifest,
@@ -352,7 +353,7 @@ impl<'a> DistributableToolchain<'a> {
352353
toolchain,
353354
profile,
354355
update_hash,
355-
dl_cfg: cfg.download_cfg(),
356+
dl_cfg: DownloadCfg::new(cfg),
356357
force,
357358
allow_downgrade: false,
358359
exists: false,
@@ -410,7 +411,7 @@ impl<'a> DistributableToolchain<'a> {
410411
toolchain: &self.desc,
411412
profile,
412413
update_hash,
413-
dl_cfg: cfg.download_cfg(),
414+
dl_cfg: DownloadCfg::new(cfg),
414415
force,
415416
allow_downgrade,
416417
exists: true,
@@ -506,7 +507,7 @@ impl<'a> DistributableToolchain<'a> {
506507
remove_components: vec![component],
507508
};
508509

509-
let download_cfg = self.toolchain.cfg.download_cfg();
510+
let download_cfg = DownloadCfg::new(self.toolchain.cfg);
510511
manifestation
511512
.update(
512513
&manifest,
@@ -523,7 +524,7 @@ impl<'a> DistributableToolchain<'a> {
523524

524525
pub async fn show_dist_version(&self) -> anyhow::Result<Option<String>> {
525526
let update_hash = self.toolchain.cfg.get_hash_file(&self.desc, false)?;
526-
let download_cfg = self.toolchain.cfg.download_cfg();
527+
let download_cfg = DownloadCfg::new(self.toolchain.cfg);
527528

528529
match crate::dist::dl_v2_manifest(download_cfg, Some(&update_hash), &self.desc).await? {
529530
Some((manifest, _)) => Ok(Some(manifest.get_rust_version()?.to_string())),

0 commit comments

Comments
 (0)