Skip to content

Commit

Permalink
refactor(config): clean up dist_root_server()
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Jul 8, 2024
1 parent 4bbd94b commit e16e606
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
27 changes: 12 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<'a> Cfg<'a> {
let notify_clone = notify_handler.clone();
let tmp_cx = temp::Context::new(
rustup_dir.join("tmp"),
dist_root_server.as_str(),
&dist_root_server,
Box::new(move |n| (notify_clone)(n.into())),
);
let dist_root = dist_root_server + "/dist";
Expand All @@ -319,7 +319,7 @@ impl<'a> Cfg<'a> {
notify_handler,
toolchain_override: None,
env_override,
dist_root_url: dist_root,
dist_root_url: dist_root.to_string(),
current_dir,
process,
};
Expand Down Expand Up @@ -940,25 +940,22 @@ impl<'a> Cfg<'a> {
}
}

fn dist_root_server(process: &Process) -> String {
match process.var("RUSTUP_DIST_SERVER") {
Ok(s) if !s.is_empty() => {
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
s
}
_ => {
fn dist_root_server(process: &Process) -> Cow<'static, str> {
process
.var("RUSTUP_DIST_SERVER")
.ok()
.and_then(utils::if_not_empty)
.inspect(|s| trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`"))
.or_else(|| {
// For backward compatibility
process
.var("RUSTUP_DIST_ROOT")
.ok()
.and_then(utils::if_not_empty)
.inspect(|url| trace!("`RUSTUP_DIST_ROOT` has been set to `{url}`"))
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned)
.as_ref()
.trim_end_matches("/dist")
.to_owned()
}
}
.map(|s| s.trim_end_matches("/dist").to_owned())
})
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_SERVER), Cow::Owned)
}

impl<'a> Debug for Cfg<'a> {
Expand Down
3 changes: 0 additions & 3 deletions src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ pub(crate) use triple::*;

pub static DEFAULT_DIST_SERVER: &str = "https://static.rust-lang.org";

// Deprecated
pub(crate) static DEFAULT_DIST_ROOT: &str = "https://static.rust-lang.org/dist";

const TOOLSTATE_MSG: &str =
"If you require these components, please install and use the latest successful build version,\n\
which you can find at <https://rust-lang.github.io/rustup-components-history>.\n\nAfter determining \
Expand Down

0 comments on commit e16e606

Please sign in to comment.