Skip to content

Commit b2c8ae2

Browse files
committed
refactor(config): extract dist_root_server()
1 parent 3a40b24 commit b2c8ae2

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/config.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,7 @@ impl<'a> Cfg<'a> {
293293
.map(|t| t.resolve(&default_host_triple))
294294
.transpose()?;
295295

296-
let dist_root_server = match non_empty_env_var("RUSTUP_DIST_SERVER", process)? {
297-
Some(s) => {
298-
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
299-
s
300-
}
301-
None => {
302-
// For backward compatibility
303-
non_empty_env_var("RUSTUP_DIST_ROOT", process)?
304-
.inspect(|url| trace!("`RUSTUP_DIST_ROOT` has been set to `{url}`"))
305-
.as_ref()
306-
.map(|root| root.trim_end_matches("/dist"))
307-
.unwrap_or(dist::DEFAULT_DIST_SERVER)
308-
.to_owned()
309-
}
310-
};
296+
let dist_root_server = dist_root_server(process)?;
311297

312298
let notify_clone = notify_handler.clone();
313299
let tmp_cx = temp::Context::new(
@@ -950,6 +936,24 @@ impl<'a> Cfg<'a> {
950936
}
951937
}
952938

939+
pub(crate) fn dist_root_server(process: &Process) -> Result<String> {
940+
Ok(match non_empty_env_var("RUSTUP_DIST_SERVER", process)? {
941+
Some(s) => {
942+
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
943+
s
944+
}
945+
None => {
946+
// For backward compatibility
947+
non_empty_env_var("RUSTUP_DIST_ROOT", process)?
948+
.inspect(|url| trace!("`RUSTUP_DIST_ROOT` has been set to `{url}`"))
949+
.as_ref()
950+
.map(|root| root.trim_end_matches("/dist"))
951+
.unwrap_or(dist::DEFAULT_DIST_SERVER)
952+
.to_owned()
953+
}
954+
})
955+
}
956+
953957
impl<'a> Debug for Cfg<'a> {
954958
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
955959
let Self {

0 commit comments

Comments
 (0)