Skip to content

Commit 12175a9

Browse files
committed
Move Cfg::get_self_update_mode() to SelfUpdateMode::from_cfg()
1 parent 586659e commit 12175a9

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/cli/rustup_mode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,8 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
889889
}
890890
}
891891
}
892-
let self_update_mode = cfg.get_self_update_mode()?;
892+
893+
let self_update_mode = SelfUpdateMode::from_cfg(cfg)?;
893894
// Priority: no-self-update feature > self_update_mode > no-self-update args.
894895
// Check for update only if rustup does **not** have the no-self-update feature,
895896
// and auto-self-update is configured to **enable**
@@ -914,7 +915,7 @@ async fn update(
914915
let mut exit_code = utils::ExitCode(0);
915916

916917
common::warn_if_host_is_emulated(cfg.process);
917-
let self_update_mode = cfg.get_self_update_mode()?;
918+
let self_update_mode = SelfUpdateMode::from_cfg(cfg)?;
918919
// Priority: no-self-update feature > self_update_mode > no-self-update args.
919920
// Update only if rustup does **not** have the no-self-update feature,
920921
// and auto-self-update is configured to **enable**

src/cli/self_update.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ pub enum SelfUpdateMode {
261261
}
262262

263263
impl SelfUpdateMode {
264+
pub(crate) fn from_cfg(cfg: &Cfg<'_>) -> anyhow::Result<Self> {
265+
if cfg.process.var("CI").is_ok() && cfg.process.var("RUSTUP_CI").is_err() {
266+
// If we're in CI (but not rustup's own CI, which wants to test this stuff!),
267+
// disable automatic self updates.
268+
return Ok(SelfUpdateMode::Disable);
269+
}
270+
271+
cfg.settings_file.with(|s| {
272+
Ok(match s.auto_self_update {
273+
Some(mode) => mode,
274+
None => SelfUpdateMode::Enable,
275+
})
276+
})
277+
}
278+
264279
pub(crate) fn as_str(&self) -> &'static str {
265280
match self {
266281
Self::Enable => "enable",

src/config.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -409,21 +409,6 @@ impl<'a> Cfg<'a> {
409409
.with(|s| Ok(s.profile.unwrap_or_default()))
410410
}
411411

412-
pub(crate) fn get_self_update_mode(&self) -> Result<SelfUpdateMode> {
413-
if self.process.var("CI").is_ok() && self.process.var("RUSTUP_CI").is_err() {
414-
// If we're in CI (but not rustup's own CI, which wants to test this stuff!),
415-
// disable automatic self updates.
416-
return Ok(SelfUpdateMode::Disable);
417-
}
418-
419-
self.settings_file.with(|s| {
420-
Ok(match s.auto_self_update {
421-
Some(mode) => mode,
422-
None => SelfUpdateMode::Enable,
423-
})
424-
})
425-
}
426-
427412
pub(crate) fn ensure_toolchains_dir(&self) -> Result<(), anyhow::Error> {
428413
utils::ensure_dir_exists("toolchains", &self.toolchains_dir, &|n| {
429414
(self.notify_handler)(n)

0 commit comments

Comments
 (0)