11//! Installation from a Rust distribution server
22
33use std:: {
4- collections:: HashSet , env, fmt, io:: Write , ops:: Deref , path:: Path , str:: FromStr , sync:: LazyLock ,
4+ collections:: HashSet ,
5+ env, fmt,
6+ io:: Write ,
7+ ops:: Deref ,
8+ path:: { Path , PathBuf } ,
9+ str:: FromStr ,
10+ sync:: LazyLock ,
511} ;
612
713use anyhow:: { Context , Result , anyhow, bail} ;
@@ -871,23 +877,48 @@ impl fmt::Display for Profile {
871877}
872878
873879pub ( crate ) struct DistOptions < ' a > {
874- pub ( crate ) cfg : & ' a Cfg < ' a > ,
875- pub ( crate ) toolchain : & ' a ToolchainDesc ,
876- pub ( crate ) profile : Profile ,
877- pub ( crate ) update_hash : & ' a Path ,
878- pub ( crate ) dl_cfg : DownloadCfg < ' a > ,
880+ pub ( super ) cfg : & ' a Cfg < ' a > ,
881+ pub ( super ) toolchain : & ' a ToolchainDesc ,
882+ profile : Profile ,
883+ pub ( super ) update_hash : PathBuf ,
884+ dl_cfg : DownloadCfg < ' a > ,
879885 /// --force bool is whether to force an update/install
880- pub ( crate ) force : bool ,
886+ force : bool ,
881887 /// --allow-downgrade
882- pub ( crate ) allow_downgrade : bool ,
888+ pub ( super ) allow_downgrade : bool ,
883889 /// toolchain already exists
884- pub ( crate ) exists : bool ,
890+ pub ( super ) exists : bool ,
885891 /// currently installed date and version
886- pub ( crate ) old_date_version : Option < ( String , String ) > ,
892+ pub ( super ) old_date_version : Option < ( String , String ) > ,
887893 /// Extra components to install from dist
888- pub ( crate ) components : & ' a [ & ' a str ] ,
894+ components : & ' a [ & ' a str ] ,
889895 /// Extra targets to install from dist
890- pub ( crate ) targets : & ' a [ & ' a str ] ,
896+ targets : & ' a [ & ' a str ] ,
897+ }
898+
899+ impl < ' a > DistOptions < ' a > {
900+ pub ( super ) fn new (
901+ components : & ' a [ & ' a str ] ,
902+ targets : & ' a [ & ' a str ] ,
903+ toolchain : & ' a ToolchainDesc ,
904+ profile : Profile ,
905+ force : bool ,
906+ cfg : & ' a Cfg < ' _ > ,
907+ ) -> Result < Self > {
908+ Ok ( Self {
909+ cfg,
910+ toolchain,
911+ profile,
912+ update_hash : cfg. get_hash_file ( toolchain, true ) ?,
913+ dl_cfg : DownloadCfg :: new ( cfg) ,
914+ force,
915+ allow_downgrade : false ,
916+ exists : false ,
917+ old_date_version : None ,
918+ components,
919+ targets,
920+ } )
921+ }
891922}
892923
893924// Installs or updates a toolchain from a dist server. If an initial
@@ -902,12 +933,12 @@ pub(crate) async fn update_from_dist(
902933) -> Result < Option < String > > {
903934 let fresh_install = !prefix. path ( ) . exists ( ) ;
904935 // fresh_install means the toolchain isn't present, but hash_exists means there is a stray hash file
905- if fresh_install && Path :: exists ( opts. update_hash ) {
936+ if fresh_install && opts. update_hash . exists ( ) {
906937 warn ! (
907938 "removing stray hash file in order to continue: {}" ,
908939 opts. update_hash. display( )
909940 ) ;
910- std:: fs:: remove_file ( opts. update_hash ) ?;
941+ std:: fs:: remove_file ( & opts. update_hash ) ?;
911942 }
912943
913944 let mut fetched = String :: new ( ) ;
@@ -960,7 +991,7 @@ pub(crate) async fn update_from_dist(
960991 let res = loop {
961992 let result = try_update_from_dist_ (
962993 & opts. dl_cfg ,
963- opts. update_hash ,
994+ & opts. update_hash ,
964995 & toolchain,
965996 match opts. exists {
966997 false => Some ( opts. profile ) ,
0 commit comments