@@ -280,6 +280,56 @@ impl SelfUpdateMode {
280280 Self :: CheckOnly => "check-only" ,
281281 }
282282 }
283+
284+ /// Optionally performs a self-update: check policy, download, apply and exit.
285+ ///
286+ /// Whether the self-update is executed is based on both compile-time and runtime
287+ /// configurations, where the priority is as follows:
288+ /// no-self-update feature > self update mode > CLI flag
289+ ///
290+ /// i.e. update only if rustup does **not** have the no-self-update feature,
291+ /// and self update mode is configured to **enable**
292+ /// and has **no** `--no-self-update` CLI flag.
293+ pub ( crate ) async fn update (
294+ & self ,
295+ should_self_update : bool ,
296+ dl_cfg : & DownloadCfg < ' _ > ,
297+ ) -> Result < ExitCode > {
298+ if cfg ! ( feature = "no-self-update" ) {
299+ info ! ( "self-update is disabled for this build of rustup" ) ;
300+ info ! ( "any updates to rustup will need to be fetched with your system package manager" ) ;
301+ return Ok ( ExitCode ( 0 ) ) ;
302+ }
303+ match self {
304+ Self :: Enable if should_self_update => ( ) ,
305+ Self :: CheckOnly => {
306+ check_rustup_update ( dl_cfg) . await ?;
307+ return Ok ( ExitCode ( 0 ) ) ;
308+ }
309+ _ => return Ok ( ExitCode ( 0 ) ) ,
310+ }
311+
312+ match self_update_permitted ( false ) ? {
313+ SelfUpdatePermission :: HardFail => {
314+ error ! ( "Unable to self-update. STOP" ) ;
315+ return Ok ( ExitCode ( 1 ) ) ;
316+ }
317+ #[ cfg( not( windows) ) ]
318+ SelfUpdatePermission :: Skip => return Ok ( ExitCode ( 0 ) ) ,
319+ SelfUpdatePermission :: Permit => { }
320+ }
321+
322+ let setup_path = prepare_update ( dl_cfg) . await ?;
323+
324+ if let Some ( setup_path) = & setup_path {
325+ return run_update ( setup_path) ;
326+ } else {
327+ // Try again in case we emitted "tool `{}` is already installed" last time.
328+ install_proxies ( dl_cfg. process ) ?;
329+ }
330+
331+ Ok ( ExitCode ( 0 ) )
332+ }
283333}
284334
285335impl ValueEnum for SelfUpdateMode {
@@ -1125,56 +1175,6 @@ pub(crate) fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermissi
11251175 Ok ( SelfUpdatePermission :: Permit )
11261176}
11271177
1128- /// Optionally performs a self-update: check policy, download, apply and exit.
1129- ///
1130- /// Whether the self-update is executed is based on both compile-time and runtime
1131- /// configurations, where the priority is as follows:
1132- /// no-self-update feature > self update mode > CLI flag
1133- ///
1134- /// i.e. update only if rustup does **not** have the no-self-update feature,
1135- /// and self update mode is configured to **enable**
1136- /// and has **no** `--no-self-update` CLI flag.
1137- pub ( crate ) async fn self_update (
1138- mode : SelfUpdateMode ,
1139- should_self_update : bool ,
1140- dl_cfg : & DownloadCfg < ' _ > ,
1141- ) -> Result < ExitCode > {
1142- if cfg ! ( feature = "no-self-update" ) {
1143- info ! ( "self-update is disabled for this build of rustup" ) ;
1144- info ! ( "any updates to rustup will need to be fetched with your system package manager" ) ;
1145- return Ok ( ExitCode ( 0 ) ) ;
1146- }
1147- match mode {
1148- SelfUpdateMode :: Enable if should_self_update => ( ) ,
1149- SelfUpdateMode :: CheckOnly => {
1150- check_rustup_update ( dl_cfg) . await ?;
1151- return Ok ( ExitCode ( 0 ) ) ;
1152- }
1153- _ => return Ok ( ExitCode ( 0 ) ) ,
1154- }
1155-
1156- match self_update_permitted ( false ) ? {
1157- SelfUpdatePermission :: HardFail => {
1158- error ! ( "Unable to self-update. STOP" ) ;
1159- return Ok ( ExitCode ( 1 ) ) ;
1160- }
1161- #[ cfg( not( windows) ) ]
1162- SelfUpdatePermission :: Skip => return Ok ( ExitCode ( 0 ) ) ,
1163- SelfUpdatePermission :: Permit => { }
1164- }
1165-
1166- let setup_path = prepare_update ( dl_cfg) . await ?;
1167-
1168- if let Some ( setup_path) = & setup_path {
1169- return run_update ( setup_path) ;
1170- } else {
1171- // Try again in case we emitted "tool `{}` is already installed" last time.
1172- install_proxies ( dl_cfg. process ) ?;
1173- }
1174-
1175- Ok ( ExitCode ( 0 ) )
1176- }
1177-
11781178/// Self update downloads rustup-init to `CARGO_HOME`/bin/rustup-init
11791179/// and runs it.
11801180///
0 commit comments