File tree 3 files changed +34
-8
lines changed
3 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,9 @@ error_chain! {
156
156
description( "failed to set permissions" )
157
157
display( "failed to set permissions for '{}'" , path. display( ) )
158
158
}
159
+ GettingCwd {
160
+ description( "couldn't get current working directory" )
161
+ }
159
162
CargoHome {
160
163
description( "couldn't find value of CARGO_HOME" )
161
164
}
Original file line number Diff line number Diff line change @@ -546,10 +546,15 @@ pub fn cargo_home() -> Result<PathBuf> {
546
546
None
547
547
} ;
548
548
549
- let cwd = try!( env:: current_dir ( ) . chain_err ( || ErrorKind :: CargoHome ) ) ;
550
- let cargo_home = env_var. clone ( ) . map ( |home| {
551
- cwd. join ( home)
552
- } ) ;
549
+ let cargo_home = if env_var. is_some ( ) {
550
+ let cwd = try!( env:: current_dir ( ) . chain_err ( || ErrorKind :: GettingCwd ) ) ;
551
+ env_var. clone ( ) . map ( |home| {
552
+ cwd. join ( home)
553
+ } )
554
+ } else {
555
+ None
556
+ } ;
557
+
553
558
let user_home = home_dir ( ) . map ( |p| p. join ( ".cargo" ) ) ;
554
559
cargo_home. or ( user_home) . ok_or ( ErrorKind :: CargoHome . into ( ) )
555
560
}
@@ -739,11 +744,17 @@ pub fn rustup_home_in_user_dir() -> Result<PathBuf> {
739
744
740
745
pub fn rustup_home ( ) -> Result < PathBuf > {
741
746
let use_rustup_dir = do_rustup_home_upgrade ( ) ;
747
+ let rustup_home_env = env:: var_os ( "RUSTUP_HOME" ) ;
748
+
749
+ let rustup_home = if rustup_home_env. is_some ( ) {
750
+ let cwd = try!( env:: current_dir ( ) . chain_err ( || ErrorKind :: GettingCwd ) ) ;
751
+ rustup_home_env. clone ( ) . map ( |home| {
752
+ cwd. join ( home)
753
+ } )
754
+ } else {
755
+ None
756
+ } ;
742
757
743
- let cwd = try!( env:: current_dir ( ) . chain_err ( || ErrorKind :: RustupHome ) ) ;
744
- let rustup_home = env:: var_os ( "RUSTUP_HOME" ) . map ( |home| {
745
- cwd. join ( home)
746
- } ) ;
747
758
let user_home = if use_rustup_dir {
748
759
dot_dir ( ".rustup" )
749
760
} else {
Original file line number Diff line number Diff line change @@ -856,6 +856,18 @@ fn multirust_dir_upgrade_rename_multirust_dir_to_rustup() {
856
856
} ) ;
857
857
}
858
858
859
+ #[ test]
860
+ fn rustup_from_non_existing_path ( ) {
861
+ setup ( & |config| {
862
+ let non_existing_dir = config. homedir . join ( ".remove_me" ) ;
863
+ let mut cmd = clitools:: cmd ( config, "rustup" , & [ "-h" ] ) ;
864
+ cmd. env_remove ( "CARGO_HOME" ) ;
865
+ cmd. current_dir ( non_existing_dir) ;
866
+ assert ! ( cmd. output( ) . unwrap( ) . status. success( ) ) ;
867
+ //expect_ok(config, &["rustup", "-h"]);
868
+ } ) ;
869
+ }
870
+
859
871
// Renaming ~/.multirust to ~/.rustup but ~/.rustup/rustup-version (rustup.sh) exists
860
872
#[ test]
861
873
fn multirust_dir_upgrade_old_rustup_exists ( ) {
You can’t perform that action at this time.
0 commit comments