Skip to content

Commit 4bbd94b

Browse files
committed
refactor(config): extract dist_root_server()
1 parent 3660792 commit 4bbd94b

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/config.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -297,24 +297,7 @@ impl<'a> Cfg<'a> {
297297
.map(|t| t.resolve(&default_host_triple))
298298
.transpose()?;
299299

300-
let dist_root_server = match process.var("RUSTUP_DIST_SERVER") {
301-
Ok(s) if !s.is_empty() => {
302-
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
303-
s
304-
}
305-
_ => {
306-
// For backward compatibility
307-
process
308-
.var("RUSTUP_DIST_ROOT")
309-
.ok()
310-
.and_then(utils::if_not_empty)
311-
.inspect(|url| trace!("`RUSTUP_DIST_ROOT` has been set to `{url}`"))
312-
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned)
313-
.as_ref()
314-
.trim_end_matches("/dist")
315-
.to_owned()
316-
}
317-
};
300+
let dist_root_server = dist_root_server(process);
318301

319302
let notify_clone = notify_handler.clone();
320303
let tmp_cx = temp::Context::new(
@@ -957,6 +940,27 @@ impl<'a> Cfg<'a> {
957940
}
958941
}
959942

943+
fn dist_root_server(process: &Process) -> String {
944+
match process.var("RUSTUP_DIST_SERVER") {
945+
Ok(s) if !s.is_empty() => {
946+
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
947+
s
948+
}
949+
_ => {
950+
// For backward compatibility
951+
process
952+
.var("RUSTUP_DIST_ROOT")
953+
.ok()
954+
.and_then(utils::if_not_empty)
955+
.inspect(|url| trace!("`RUSTUP_DIST_ROOT` has been set to `{url}`"))
956+
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned)
957+
.as_ref()
958+
.trim_end_matches("/dist")
959+
.to_owned()
960+
}
961+
}
962+
}
963+
960964
impl<'a> Debug for Cfg<'a> {
961965
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
962966
let Self {

0 commit comments

Comments
 (0)