-
Notifications
You must be signed in to change notification settings - Fork 984
refactor(cli/rustup-mode): merge self-update checking logic in rustup update
#4562
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -979,12 +979,15 @@ async fn maybe_install_rust(opts: InstallOpts<'_>, cfg: &mut Cfg<'_>) -> Result< | |
| Ok(()) | ||
| } | ||
|
|
||
| /// Whether the self-update functionality is enabled during compilation. | ||
| pub(crate) const CFG_SELF_UPDATE: bool = !cfg!(feature = "no-self-update"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redoing something that I undid only recently. I don't see much value in it -- it just obscures the original meaning and saves a few characters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @djc I still think the double negation here in |
||
|
|
||
| pub(crate) fn uninstall( | ||
| no_prompt: bool, | ||
| no_modify_path: bool, | ||
| process: &Process, | ||
| ) -> Result<utils::ExitCode> { | ||
| if cfg!(feature = "no-self-update") { | ||
| if !CFG_SELF_UPDATE { | ||
| error!("self-uninstall is disabled for this build of rustup"); | ||
| error!("you should probably use your system package manager to uninstall rustup"); | ||
| return Ok(utils::ExitCode(1)); | ||
|
|
@@ -1169,10 +1172,10 @@ pub(crate) async fn update(cfg: &Cfg<'_>) -> Result<utils::ExitCode> { | |
| common::warn_if_host_is_emulated(cfg.process); | ||
|
|
||
| use SelfUpdatePermission::*; | ||
| let update_permitted = if cfg!(feature = "no-self-update") { | ||
| HardFail | ||
| } else { | ||
| let update_permitted = if CFG_SELF_UPDATE { | ||
| self_update_permitted(true)? | ||
| } else { | ||
| HardFail | ||
| }; | ||
| match update_permitted { | ||
| HardFail => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the reason, I think you can
cfg!()instead of an attribute.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not having explained the full background until now, but when looking at #4565 I realized that the self-update cleanup code is very curiously written in two parts, so I want to merge them together first to make the overall logic clearer.
However, since this change is not directly related to #4565, I planned on making two separate PRs...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@djc I'm not entirely sure about your proposals, but maybe this could be simplified to just the following?
... the idea is that this block covers all the cases where
self_update()is not executed, and when I add the extraif self_updateblock in a second PR, it'll be clearer when each case is handled.Or you might have different opinions regarding the fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made #4566 to hopefully make my original intentions clearer.