@@ -488,9 +488,25 @@ fn determine_paths(cwd: &Path) -> Option<Paths> {
488
488
fs:: metadata ( & path) . ok ( ) . map ( |_| path)
489
489
}
490
490
491
+ // Strategy to determine where to put files:
492
+ //
493
+ // 1) Use the environment variable CARGO_HOME if it exists.
494
+ // 2) Use the XDG specification if it exists.
495
+ // 3) Use the legacy location (~/.cargo) if it exists.
496
+ // 4) Fall back to the XDG specification if all of the above things fail.
497
+
498
+ // 1)
499
+ if let Some ( v) = env:: var_os ( "CARGO_HOME" ) . map ( |p| cwd. join ( p) ) {
500
+ return Some ( Paths {
501
+ bin : v. clone ( ) ,
502
+ cache : v. clone ( ) ,
503
+ config : v,
504
+ additional_configs : vec ! [ ] ,
505
+ } ) ;
506
+ }
507
+
491
508
let user_home = if let Some ( p) = env:: home_dir ( ) { p } else { return None ; } ;
492
509
493
- let home_var = env:: var_os ( "CARGO_HOME" ) . map ( |home| cwd. join ( home) ) ;
494
510
let xdg = xdg:: BaseDirectories :: with_prefix ( "cargo" ) ;
495
511
let legacy = user_home. join ( ".cargo" ) ;
496
512
@@ -502,26 +518,13 @@ fn determine_paths(cwd: &Path) -> Option<Paths> {
502
518
let mut bin: Option < PathBuf > ;
503
519
let mut cache: Option < PathBuf > ;
504
520
let mut config: Option < PathBuf > ;
505
- let additional_configs: Option < Vec < PathBuf > > ;
506
-
507
- // Strategy to determine where to put files:
508
- //
509
- // 1) Use the environment variable CARGO_HOME if it exists.
510
- // 2) Use the XDG specification if it exists.
511
- // 3) Use the legacy location (~/.cargo) if it exists.
512
- // 4) Fall back to the XDG specification if all of the above things fail.
513
-
514
- // 1)
515
- bin = home_var. clone ( ) ;
516
- cache = home_var. clone ( ) ;
517
- config = home_var. clone ( ) ;
518
- additional_configs = home_var. map ( |_| vec ! [ ] ) ;
521
+ let additional_configs: Vec < PathBuf > ;
519
522
520
523
// 2)
521
- bin = bin . or_else ( || path_exists ( bin_xdgish. clone ( ) ) ) ;
522
- cache = cache . or_else ( || path_exists ( cache_xdg. clone ( ) ) ) ;
523
- config = config . or_else ( || path_exists ( config_xdg. clone ( ) ) ) ;
524
- let additional_configs = additional_configs . unwrap_or ( additional_configs_xdg) ;
524
+ bin = path_exists ( bin_xdgish. clone ( ) ) ;
525
+ cache = path_exists ( cache_xdg. clone ( ) ) ;
526
+ config = path_exists ( config_xdg. clone ( ) ) ;
527
+ additional_configs = additional_configs_xdg;
525
528
526
529
// 3)
527
530
if let Some ( l) = path_exists ( legacy) {
0 commit comments