@@ -200,30 +200,41 @@ fn show_channel_updates(
200200 Ok ( ( ) )
201201}
202202
203- pub fn update_all_channels ( cfg : & Cfg , self_update : bool , force_update : bool ) -> Result < ( ) > {
203+ pub fn update_all_channels ( cfg : & Cfg , do_self_update : bool , force_update : bool ) -> Result < ( ) > {
204204 let toolchains = cfg. update_all_channels ( force_update) ?;
205205
206206 if toolchains. is_empty ( ) {
207207 info ! ( "no updatable toolchains installed" ) ;
208208 }
209209
210- let setup_path = if self_update {
211- self_update:: prepare_update ( ) ?
212- } else {
213- None
214- } ;
210+ let show_channel_updates = || {
211+ if !toolchains. is_empty ( ) {
212+ println ! ( "" ) ;
215213
216- if !toolchains. is_empty ( ) {
217- println ! ( "" ) ;
214+ show_channel_updates ( cfg, toolchains) ?;
215+ }
216+ Ok ( ( ) )
217+ } ;
218218
219- show_channel_updates ( cfg, toolchains) ?;
219+ if do_self_update {
220+ self_update ( show_channel_updates)
221+ } else {
222+ show_channel_updates ( )
220223 }
224+ }
225+
226+ pub fn self_update < F > ( before_restart : F ) -> Result < ( ) >
227+ where F : FnOnce ( ) -> Result < ( ) >
228+ {
229+ let setup_path = self_update:: prepare_update ( ) ?;
230+
231+ before_restart ( ) ?;
221232
222233 if let Some ( ref setup_path) = setup_path {
223234 self_update:: run_update ( setup_path) ?;
224235
225236 unreachable ! ( ) ; // update exits on success
226- } else if self_update {
237+ } else {
227238 // Try again in case we emitted "tool `{}` is already installed" last time.
228239 self_update:: install_proxies ( ) ?;
229240 }
0 commit comments