File tree 1 file changed +16
-7
lines changed
1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ pub use netrc::{Authenticator, Netrc};
33
33
use std:: fs;
34
34
use std:: io;
35
35
use std:: io:: ErrorKind ;
36
+ #[ cfg( windows) ]
37
+ use std:: iter:: repeat;
36
38
use std:: path:: { Path , PathBuf } ;
37
39
use std:: result;
38
40
@@ -82,14 +84,21 @@ impl Netrc {
82
84
83
85
/// Search a netrc file.
84
86
///
85
- /// Look up the `NETRC` environment variable if it is defined else that the
86
- /// default `$HOME/.netrc` file .
87
+ /// Look up the `NETRC` environment variable if it is defined else use the .netrc (or _netrc
88
+ /// file on windows) in the user's home directory .
87
89
pub fn get_file ( ) -> Option < PathBuf > {
88
- std:: env:: var ( "NETRC" )
89
- . map ( |x| PathBuf :: from ( & x) )
90
- . or ( std:: env:: var ( "HOME" ) . map ( |h| Path :: new ( & h) . join ( ".netrc" ) ) )
91
- . ok ( )
92
- . and_then ( |f| if f. exists ( ) { Some ( f) } else { None } )
90
+ let env_var = std:: env:: var ( "NETRC" ) . map ( PathBuf :: from) ;
91
+
92
+ #[ cfg( windows) ]
93
+ let default = std:: env:: var ( "USERPROFILE" )
94
+ . into_iter ( )
95
+ . flat_map ( |home| repeat ( home) . zip ( [ ".netrc" , "_netrc" ] ) )
96
+ . map ( |( home, file) | PathBuf :: from ( home) . join ( file) ) ;
97
+
98
+ #[ cfg( not( windows) ) ]
99
+ let default = std:: env:: var ( "HOME" ) . map ( |home| PathBuf :: from ( home) . join ( ".netrc" ) ) ;
100
+
101
+ env_var. into_iter ( ) . chain ( default) . find ( |f| f. exists ( ) )
93
102
}
94
103
}
95
104
You can’t perform that action at this time.
0 commit comments