@@ -1577,25 +1577,27 @@ impl GlobalContext {
15771577 }
15781578 }
15791579
1580- fn walk_tree < F > ( & self , pwd : & Path , home : & Path , mut walk : F ) -> CargoResult < ( ) >
1580+ fn walk_tree < F > ( & self , pwd : & Path , cargo_home : & Path , mut walk : F ) -> CargoResult < ( ) >
15811581 where
15821582 F : FnMut ( & Path ) -> CargoResult < ( ) > ,
15831583 {
15841584 let mut stash: HashSet < PathBuf > = HashSet :: new ( ) ;
15851585
15861586 for current in paths:: ancestors ( pwd, self . search_stop_path . as_deref ( ) ) {
1587+ // Be aware `current` may be the parent of the `$CARGO_HOME`, in this case the next line also walk the `$CARGO_HOME`.
15871588 if let Some ( path) = self . get_file_path ( & current. join ( ".cargo" ) , "config" , true ) ? {
15881589 walk ( & path) ?;
15891590 stash. insert ( path) ;
15901591 }
15911592 }
15921593
1593- // Once we're done, also be sure to walk the home directory even if it's not
1594- // in our history to be sure we pick up that standard location for
1595- // information.
1596- if let Some ( path) = self . get_file_path ( home, "config" , true ) ? {
1597- if !stash. contains ( & path) {
1598- walk ( & path) ?;
1594+ let cargo_home_parent = cargo_home. parent ( ) . unwrap_or ( cargo_home) ;
1595+ // If we haven't walked the $CARGO_HOME directory yet, walk it to pick up that standard location for information.
1596+ if !pwd. starts_with ( cargo_home_parent) {
1597+ if let Some ( path) = self . get_file_path ( cargo_home, "config" , true ) ? {
1598+ if !stash. contains ( & path) {
1599+ walk ( & path) ?;
1600+ }
15991601 }
16001602 }
16011603
0 commit comments