File tree 3 files changed +14
-18
lines changed
3 files changed +14
-18
lines changed Original file line number Diff line number Diff line change @@ -608,20 +608,16 @@ impl Error for JoinPathsError {
608
608
///
609
609
/// # Windows
610
610
///
611
- /// - Returns the value of the 'HOME' environment variable if it is set
612
- /// (including to an empty string).
613
- /// - Otherwise, returns the value of the 'USERPROFILE' environment variable if it is set
614
- /// (including to an empty string).
615
- /// - If both do not exist, [`GetUserProfileDirectory`][msdn] is used to return the path.
611
+ /// - Returns the value of the 'USERPROFILE' environment variable if it is set, and is not an empty string.
612
+ /// - Otherwise, [`GetUserProfileDirectory`][msdn] is used to return the path. This may change in the future.
616
613
///
617
614
/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectorya
618
615
///
619
- /// # Deprecation
616
+ /// In UWP (Universal Windows Platform) targets this function is unimplemented and always returns `None`.
620
617
///
621
- /// This function is deprecated because the behavior on Windows is not correct.
622
- /// The 'HOME' environment variable is not standard on Windows, and may not produce
623
- /// desired results; for instance, under Cygwin or Mingw it will return `/home/you`
624
- /// when it should return `C:\Users\you`.
618
+ /// Before Rust CURRENT_RUSTC_VERSION, this function used to return the value of the 'HOME' environment variable
619
+ /// on Windows, which in Cygwin or Mingw environments could return non-standard paths like `/home/you`
620
+ /// instead of `C:\Users\you`.
625
621
///
626
622
/// # Examples
627
623
///
Original file line number Diff line number Diff line change @@ -377,8 +377,8 @@ fn home_dir_crt() -> Option<PathBuf> {
377
377
}
378
378
379
379
pub fn home_dir ( ) -> Option < PathBuf > {
380
- crate :: env:: var_os ( "HOME " )
381
- . or_else ( || crate :: env :: var_os ( "USERPROFILE" ) )
380
+ crate :: env:: var_os ( "USERPROFILE " )
381
+ . filter ( |s| !s . is_empty ( ) )
382
382
. map ( PathBuf :: from)
383
383
. or_else ( home_dir_crt)
384
384
}
Original file line number Diff line number Diff line change @@ -122,19 +122,19 @@ fn env_home_dir() {
122
122
123
123
assert!( home_dir( ) . is_some( ) ) ;
124
124
125
- set_var( "HOME" , "/home/MountainView" ) ;
125
+ set_var( "HOME" , "/home/PaloAlto" ) ;
126
+ assert_ne!( home_dir( ) , Some ( PathBuf :: from( "/home/PaloAlto" ) ) , "HOME must not be used" ) ;
127
+
128
+ set_var( "USERPROFILE" , "/home/MountainView" ) ;
126
129
assert_eq!( home_dir( ) , Some ( PathBuf :: from( "/home/MountainView" ) ) ) ;
127
130
128
131
remove_var( "HOME" ) ;
129
132
130
- set_var( "USERPROFILE" , "/home/MountainView" ) ;
131
133
assert_eq!( home_dir( ) , Some ( PathBuf :: from( "/home/MountainView" ) ) ) ;
132
134
133
- set_var( "HOME" , "/home/MountainView" ) ;
134
- set_var( "USERPROFILE" , "/home/PaloAlto" ) ;
135
- assert_eq!( home_dir( ) , Some ( PathBuf :: from( "/home/MountainView" ) ) ) ;
135
+ set_var( "USERPROFILE" , "" ) ;
136
+ assert_ne!( home_dir( ) , Some ( PathBuf :: from( "" ) ) , "Empty USERPROFILE must be ignored" ) ;
136
137
137
- remove_var( "HOME" ) ;
138
138
remove_var( "USERPROFILE" ) ;
139
139
140
140
if let Some ( oldhome) = oldhome { set_var( "HOME" , oldhome) ; }
You can’t perform that action at this time.
0 commit comments