Skip to content

Commit 8128266

Browse files
committed
Re-arrange download_cfg
Most of download_cfg belonged on Config; the remained on DistributableToolchain.
1 parent d8d131d commit 8128266

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::sync::Arc;
99

1010
use pgp::{Deserializable, SignedPublicKey};
1111

12+
use crate::dist::download::DownloadCfg;
1213
use crate::dist::{dist, temp};
1314
use crate::errors::*;
1415
use crate::fallback_settings::FallbackSettings;
@@ -224,6 +225,20 @@ impl Cfg {
224225
Ok(cfg)
225226
}
226227

228+
/// construct a download configuration
229+
pub fn download_cfg<'a>(
230+
&'a self,
231+
notify_handler: &'a dyn Fn(crate::dist::Notification<'_>),
232+
) -> DownloadCfg<'a> {
233+
DownloadCfg {
234+
dist_root: &self.dist_root_url,
235+
temp_cfg: &self.temp_cfg,
236+
download_dir: &self.download_dir,
237+
notify_handler: notify_handler,
238+
pgp_keys: self.get_pgp_keys(),
239+
}
240+
}
241+
227242
pub fn get_pgp_keys(&self) -> &[PgpPublicKey] {
228243
&self.pgp_keys
229244
}
@@ -655,6 +670,7 @@ impl Cfg {
655670
return Ok(None);
656671
}
657672

673+
// XXX: This could actually consider all distributable toolchains in principle.
658674
for fallback in &["nightly", "beta", "stable"] {
659675
let fallback = self.get_toolchain(fallback, false)?;
660676
if fallback.exists() {

src/toolchain.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,6 @@ impl<'a> Toolchain<'a> {
139139
Ok(())
140140
}
141141

142-
// XXX: Move to Config with a notify handler parameter
143-
fn download_cfg(&self) -> DownloadCfg<'_> {
144-
DownloadCfg {
145-
dist_root: &self.cfg.dist_root_url,
146-
temp_cfg: &self.cfg.temp_cfg,
147-
download_dir: &self.cfg.download_dir,
148-
notify_handler: &*self.dist_handler,
149-
pgp_keys: self.cfg.get_pgp_keys(),
150-
}
151-
}
152-
153142
// Custom only
154143
pub fn is_custom(&self) -> bool {
155144
ToolchainDesc::from_str(&self.name).is_err()
@@ -531,8 +520,8 @@ impl<'a> DistributableToolchain<'a> {
531520
&manifest,
532521
changes,
533522
false,
534-
&self.0.download_cfg(),
535-
&self.0.download_cfg().notify_handler,
523+
&self.download_cfg(),
524+
&self.download_cfg().notify_handler,
536525
&toolchain.manifest_name(),
537526
false,
538527
)?;
@@ -601,6 +590,10 @@ impl<'a> DistributableToolchain<'a> {
601590
Ok(ToolchainDesc::from_str(&self.0.name)?)
602591
}
603592

593+
fn download_cfg(&self) -> DownloadCfg<'_> {
594+
self.0.cfg.download_cfg(&*self.0.dist_handler)
595+
}
596+
604597
// Installed only?
605598
fn get_component_suggestion(
606599
&self,
@@ -714,7 +707,7 @@ impl<'a> DistributableToolchain<'a> {
714707
desc: &self.desc()?,
715708
profile: self.0.cfg.get_profile()?,
716709
update_hash: Some(&update_hash),
717-
dl_cfg: self.0.download_cfg(),
710+
dl_cfg: self.download_cfg(),
718711
force_update,
719712
allow_downgrade,
720713
exists: self.0.exists(),
@@ -735,7 +728,7 @@ impl<'a> DistributableToolchain<'a> {
735728
desc: &self.desc()?,
736729
profile: self.0.cfg.get_profile()?,
737730
update_hash: Some(&update_hash),
738-
dl_cfg: self.0.download_cfg(),
731+
dl_cfg: self.download_cfg(),
739732
force_update: false,
740733
allow_downgrade: false,
741734
exists: false,
@@ -862,8 +855,8 @@ impl<'a> DistributableToolchain<'a> {
862855
&manifest,
863856
changes,
864857
false,
865-
&self.0.download_cfg(),
866-
&self.0.download_cfg().notify_handler,
858+
&self.download_cfg(),
859+
&self.download_cfg().notify_handler,
867860
&toolchain.manifest_name(),
868861
false,
869862
)?;
@@ -879,7 +872,7 @@ impl<'a> DistributableToolchain<'a> {
879872
let update_hash = self.update_hash()?;
880873

881874
match crate::dist::dist::dl_v2_manifest(
882-
self.0.download_cfg(),
875+
self.download_cfg(),
883876
Some(&update_hash),
884877
&self.desc()?,
885878
)? {

0 commit comments

Comments
 (0)