@@ -50,6 +50,7 @@ use serde::{Deserialize, Serialize};
5050use termcolor:: Color ;
5151use tracing:: { error, info, trace, warn} ;
5252
53+ use crate :: dist:: download:: DownloadCfg ;
5354use crate :: {
5455 DUP_TOOLS , TOOLS ,
5556 cli:: {
@@ -1112,7 +1113,7 @@ pub(crate) fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermissi
11121113}
11131114
11141115/// Performs all of a self-update: check policy, download, apply and exit.
1115- pub ( crate ) async fn self_update ( process : & Process ) -> Result < utils:: ExitCode > {
1116+ pub ( crate ) async fn self_update ( dl_cfg : & DownloadCfg < ' _ > ) -> Result < utils:: ExitCode > {
11161117 match self_update_permitted ( false ) ? {
11171118 SelfUpdatePermission :: HardFail => {
11181119 error ! ( "Unable to self-update. STOP" ) ;
@@ -1123,13 +1124,13 @@ pub(crate) async fn self_update(process: &Process) -> Result<utils::ExitCode> {
11231124 SelfUpdatePermission :: Permit => { }
11241125 }
11251126
1126- let setup_path = prepare_update ( process ) . await ?;
1127+ let setup_path = prepare_update ( dl_cfg ) . await ?;
11271128
11281129 if let Some ( setup_path) = & setup_path {
11291130 return run_update ( setup_path) ;
11301131 } else {
11311132 // Try again in case we emitted "tool `{}` is already installed" last time.
1132- install_proxies ( process) ?;
1133+ install_proxies ( dl_cfg . process ) ?;
11331134 }
11341135
11351136 Ok ( utils:: ExitCode ( 0 ) )
@@ -1174,7 +1175,7 @@ pub(crate) async fn update(cfg: &Cfg<'_>) -> Result<utils::ExitCode> {
11741175 Permit => { }
11751176 }
11761177
1177- match prepare_update ( cfg. process ) . await ? {
1178+ match prepare_update ( & DownloadCfg :: new ( cfg) ) . await ? {
11781179 Some ( setup_path) => {
11791180 let Some ( version) = get_and_parse_new_rustup_version ( & setup_path) else {
11801181 error ! ( "failed to get rustup version" ) ;
@@ -1227,8 +1228,8 @@ fn parse_new_rustup_version(version: String) -> String {
12271228 String :: from ( matched_version)
12281229}
12291230
1230- pub ( crate ) async fn prepare_update ( process : & Process ) -> Result < Option < PathBuf > > {
1231- let cargo_home = process. cargo_home ( ) ?;
1231+ pub ( crate ) async fn prepare_update ( dl_cfg : & DownloadCfg < ' _ > ) -> Result < Option < PathBuf > > {
1232+ let cargo_home = dl_cfg . process . cargo_home ( ) ?;
12321233 let rustup_path = cargo_home. join ( format ! ( "bin{MAIN_SEPARATOR}rustup{EXE_SUFFIX}" ) ) ;
12331234 let setup_path = cargo_home. join ( format ! ( "bin{MAIN_SEPARATOR}rustup-init{EXE_SUFFIX}" ) ) ;
12341235
@@ -1253,19 +1254,19 @@ pub(crate) async fn prepare_update(process: &Process) -> Result<Option<PathBuf>>
12531254 let triple = dist:: TargetTriple :: from_host ( process) . unwrap_or ( triple) ;
12541255
12551256 // Get update root.
1256- let update_root = update_root ( process) ;
1257+ let update_root = update_root ( dl_cfg . process ) ;
12571258
12581259 // Get current version
12591260 let current_version = env ! ( "CARGO_PKG_VERSION" ) ;
12601261
12611262 // Get available version
12621263 info ! ( "checking for self-update (current version: {current_version})" ) ;
1263- let available_version = match process. var_opt ( "RUSTUP_VERSION" ) ? {
1264+ let available_version = match dl_cfg . process . var_opt ( "RUSTUP_VERSION" ) ? {
12641265 Some ( ver) => {
12651266 info ! ( "`RUSTUP_VERSION` has been set to `{ver}`" ) ;
12661267 ver
12671268 }
1268- None => get_available_rustup_version ( process ) . await ?,
1269+ None => get_available_rustup_version ( dl_cfg ) . await ?,
12691270 } ;
12701271
12711272 // If up-to-date
@@ -1281,16 +1282,23 @@ pub(crate) async fn prepare_update(process: &Process) -> Result<Option<PathBuf>>
12811282
12821283 // Download new version
12831284 info ! ( "downloading self-update (new version: {available_version})" ) ;
1284- download_file ( & download_url, & setup_path, None , & |_| ( ) , process) . await ?;
1285+ download_file (
1286+ & download_url,
1287+ & setup_path,
1288+ None ,
1289+ & dl_cfg. notifier ,
1290+ dl_cfg. process ,
1291+ )
1292+ . await ?;
12851293
12861294 // Mark as executable
12871295 utils:: make_executable ( & setup_path) ?;
12881296
12891297 Ok ( Some ( setup_path) )
12901298}
12911299
1292- async fn get_available_rustup_version ( process : & Process ) -> Result < String > {
1293- let update_root = update_root ( process) ;
1300+ async fn get_available_rustup_version ( dl_cfg : & DownloadCfg < ' _ > ) -> Result < String > {
1301+ let update_root = update_root ( dl_cfg . process ) ;
12941302 let tempdir = tempfile:: Builder :: new ( )
12951303 . prefix ( "rustup-update" )
12961304 . tempdir ( )
@@ -1300,7 +1308,14 @@ async fn get_available_rustup_version(process: &Process) -> Result<String> {
13001308 let release_file_url = format ! ( "{update_root}/release-stable.toml" ) ;
13011309 let release_file_url = utils:: parse_url ( & release_file_url) ?;
13021310 let release_file = tempdir. path ( ) . join ( "release-stable.toml" ) ;
1303- download_file ( & release_file_url, & release_file, None , & |_| ( ) , process) . await ?;
1311+ download_file (
1312+ & release_file_url,
1313+ & release_file,
1314+ None ,
1315+ & dl_cfg. notifier ,
1316+ dl_cfg. process ,
1317+ )
1318+ . await ?;
13041319 let release_toml_str = utils:: read_file ( "rustup release" , & release_file) ?;
13051320 let release_toml = toml:: from_str :: < RustupManifest > ( & release_toml_str)
13061321 . context ( "unable to parse rustup release file" ) ?;
@@ -1348,13 +1363,13 @@ impl fmt::Display for SchemaVersion {
13481363}
13491364
13501365/// Returns whether an update was available
1351- pub ( crate ) async fn check_rustup_update ( process : & Process ) -> anyhow:: Result < bool > {
1352- let mut t = process. stdout ( ) ;
1366+ pub ( crate ) async fn check_rustup_update ( dl_cfg : & DownloadCfg < ' _ > ) -> anyhow:: Result < bool > {
1367+ let mut t = dl_cfg . process . stdout ( ) ;
13531368 // Get current rustup version
13541369 let current_version = env ! ( "CARGO_PKG_VERSION" ) ;
13551370
13561371 // Get available rustup version
1357- let available_version = get_available_rustup_version ( process ) . await ?;
1372+ let available_version = get_available_rustup_version ( dl_cfg ) . await ?;
13581373
13591374 let _ = t. attr ( Attr :: Bold ) ;
13601375 write ! ( t. lock( ) , "rustup - " ) ?;
0 commit comments