Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make auto-self-update setting work when no-self-update feature is enabled #3051

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,13 +1032,25 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
cfg.temp_cfg.clean();
}

if !self_update::NEVER_SELF_UPDATE && self_update_mode == SelfUpdateMode::CheckOnly {
check_rustup_update()?;
match (&self_update_mode, self_update::NEVER_SELF_UPDATE) {
(SelfUpdateMode::CheckOnly, _) | (SelfUpdateMode::Enable, true) => check_rustup_update()?,
(SelfUpdateMode::Disable, _) | (SelfUpdateMode::Enable, false) => {}
}

if self_update::NEVER_SELF_UPDATE {
if self_update::NEVER_SELF_UPDATE && self_update_mode == SelfUpdateMode::Enable {
let mut args = crate::process().args_os();
let arg0 = args.next().map(PathBuf::from);
let arg0 = arg0
.as_ref()
.and_then(|a| a.to_str())
.ok_or(CLIError::NoExeName)?;

info!("self-update is disabled for this build of rustup");
info!("any updates to rustup will need to be fetched with your system package manager")
info!("any updates to rustup will need to be fetched with your system package manager");
info!(
"to suppress this message, run `{} set auto-self-update disable`",
arg0,
);
}

Ok(utils::ExitCode(0))
Expand Down Expand Up @@ -1608,16 +1620,19 @@ fn set_profile(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
}

fn set_auto_self_update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
if self_update::NEVER_SELF_UPDATE {
cfg.set_auto_self_update(m.value_of("auto-self-update-mode").unwrap())?;

if self_update::NEVER_SELF_UPDATE && cfg.get_self_update_mode()? == SelfUpdateMode::Enable {
let mut args = crate::process().args_os();
let arg0 = args.next().map(PathBuf::from);
let arg0 = arg0
.as_ref()
.and_then(|a| a.to_str())
.ok_or(CLIError::NoExeName)?;
warn!("{} is built with the no-self-update feature: setting auto-self-update will not have any effect.",arg0);
warn!("{} is built with the no-self-update feature", arg0);
warn!("setting auto-self-update to enable won't lead to updates being installed");
}
cfg.set_auto_self_update(m.value_of("auto-self-update-mode").unwrap())?;

Ok(utils::ExitCode(0))
}

Expand Down