Skip to content

Commit ab5d84e

Browse files
committed
refactor(self-update): extract update_root()
1 parent 1de2394 commit ab5d84e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/cli/self_update.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ These components can be acquired through a Visual Studio installer.
333333

334334
static UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";
335335

336+
fn update_root() -> String {
337+
process()
338+
.var("RUSTUP_UPDATE_ROOT")
339+
.unwrap_or_else(|_| String::from(UPDATE_ROOT))
340+
}
341+
336342
/// `CARGO_HOME` suitable for display, possibly with $HOME
337343
/// substituted for the directory prefix
338344
fn canonical_cargo_home() -> Result<Cow<'static, str>> {
@@ -1178,9 +1184,7 @@ pub(crate) fn prepare_update() -> Result<Option<PathBuf>> {
11781184
let triple = dist::TargetTriple::from_host().unwrap_or(triple);
11791185

11801186
// Get update root.
1181-
let update_root = process()
1182-
.var("RUSTUP_UPDATE_ROOT")
1183-
.unwrap_or_else(|_| String::from(UPDATE_ROOT));
1187+
let update_root = update_root();
11841188

11851189
// Get current version
11861190
let current_version = env!("CARGO_PKG_VERSION");
@@ -1211,9 +1215,7 @@ pub(crate) fn prepare_update() -> Result<Option<PathBuf>> {
12111215
}
12121216

12131217
pub(crate) fn get_available_rustup_version() -> Result<String> {
1214-
let update_root = process()
1215-
.var("RUSTUP_UPDATE_ROOT")
1216-
.unwrap_or_else(|_| String::from(UPDATE_ROOT));
1218+
let update_root = update_root();
12171219
let tempdir = tempfile::Builder::new()
12181220
.prefix("rustup-update")
12191221
.tempdir()

0 commit comments

Comments
 (0)