11use std:: cell:: RefCell ;
22use std:: collections:: BTreeMap ;
33use std:: path:: { Path , PathBuf } ;
4+ use std:: str:: FromStr ;
45
56use anyhow:: { Context , Result } ;
67
8+ use crate :: cli:: self_update:: SelfUpdateMode ;
79use crate :: errors:: * ;
810use crate :: notifications:: * ;
911use crate :: toml_utils:: * ;
@@ -77,7 +79,7 @@ pub struct Settings {
7779 pub profile : Option < String > ,
7880 pub overrides : BTreeMap < String , String > ,
7981 pub pgp_keys : Option < String > ,
80- pub auto_self_update : Option < String > ,
82+ pub auto_self_update : Option < SelfUpdateMode > ,
8183}
8284
8385impl Default for Settings {
@@ -89,7 +91,7 @@ impl Default for Settings {
8991 profile : Some ( "default" . to_owned ( ) ) ,
9092 overrides : BTreeMap :: new ( ) ,
9193 pgp_keys : None ,
92- auto_self_update : Some ( "enable" . to_owned ( ) ) ,
94+ auto_self_update : Some ( SelfUpdateMode :: Enable ) ,
9395 }
9496 }
9597}
@@ -148,14 +150,21 @@ impl Settings {
148150 if !SUPPORTED_METADATA_VERSIONS . contains ( & & * version) {
149151 return Err ( RustupError :: UnknownMetadataVersion ( version) . into ( ) ) ;
150152 }
153+ let auto_self_update = match get_opt_string ( & mut table, "auto_self_update" , path) ? {
154+ Some ( auto_self_update) => match SelfUpdateMode :: from_str ( auto_self_update. as_str ( ) ) {
155+ Ok ( mode) => Some ( mode) ,
156+ Err ( _) => None ,
157+ } ,
158+ None => None ,
159+ } ;
151160 Ok ( Self {
152161 version,
153162 default_host_triple : get_opt_string ( & mut table, "default_host_triple" , path) ?,
154163 default_toolchain : get_opt_string ( & mut table, "default_toolchain" , path) ?,
155164 profile : get_opt_string ( & mut table, "profile" , path) ?,
156165 overrides : Self :: table_to_overrides ( & mut table, path) ?,
157166 pgp_keys : get_opt_string ( & mut table, "pgp_keys" , path) ?,
158- auto_self_update : get_opt_string ( & mut table , "auto_self_update" , path ) ? ,
167+ auto_self_update,
159168 } )
160169 }
161170 pub fn into_toml ( self ) -> toml:: value:: Table {
@@ -180,7 +189,10 @@ impl Settings {
180189 }
181190
182191 if let Some ( v) = self . auto_self_update {
183- result. insert ( "auto_self_update" . to_owned ( ) , toml:: Value :: String ( v) ) ;
192+ result. insert (
193+ "auto_self_update" . to_owned ( ) ,
194+ toml:: Value :: String ( v. to_string ( ) ) ,
195+ ) ;
184196 }
185197
186198 let overrides = Self :: overrides_to_table ( self . overrides ) ;
0 commit comments