@@ -1577,25 +1577,27 @@ impl GlobalContext {
1577
1577
}
1578
1578
}
1579
1579
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 < ( ) >
1581
1581
where
1582
1582
F : FnMut ( & Path ) -> CargoResult < ( ) > ,
1583
1583
{
1584
1584
let mut stash: HashSet < PathBuf > = HashSet :: new ( ) ;
1585
1585
1586
1586
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`.
1587
1588
if let Some ( path) = self . get_file_path ( & current. join ( ".cargo" ) , "config" , true ) ? {
1588
1589
walk ( & path) ?;
1589
1590
stash. insert ( path) ;
1590
1591
}
1591
1592
}
1592
1593
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
+ }
1599
1601
}
1600
1602
}
1601
1603
0 commit comments