Skip to content

Commit 6efc30a

Browse files
committed
Move Cfg::get_self_update_mode() to SelfUpdateMode::from_cfg()
1 parent 854f1c7 commit 6efc30a

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/cli/rustup_mode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
829829
}
830830
}
831831

832-
let self_update_mode = cfg.get_self_update_mode()?;
832+
let self_update_mode = SelfUpdateMode::from_cfg(cfg)?;
833833
// Priority: no-self-update feature > self_update_mode > no-self-update args.
834834
// Check for update only if rustup does **not** have the no-self-update feature,
835835
// and auto-self-update is configured to **enable**
@@ -854,7 +854,7 @@ async fn update(
854854
let mut exit_code = utils::ExitCode(0);
855855

856856
common::warn_if_host_is_emulated(cfg.process);
857-
let self_update_mode = cfg.get_self_update_mode()?;
857+
let self_update_mode = SelfUpdateMode::from_cfg(cfg)?;
858858
// Priority: no-self-update feature > self_update_mode > no-self-update args.
859859
// Update only if rustup does **not** have the no-self-update feature,
860860
// 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)