@@ -1577,25 +1577,31 @@ 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
+ // Beware `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
+ // The convention `$CARGO_HOME` can be changed by ENV `CARGO_HOME`, like renaming $HOME/.cargo into $HOME/my_home,
1595
+ // So the `config` must be joined with the actual `cargo_home`.
1596
+ let home_config_without_extention = cargo_home. join ( "config" ) ;
1597
+ let already_walked = stash. contains ( & home_config_without_extention) ;
1598
+
1599
+ // If we haven't walked the $CARGO_HOME directory yet, walk it to pick up that standard location for information.
1600
+ if !already_walked {
1601
+ if let Some ( path) = self . get_file_path ( cargo_home, "config" , true ) ? {
1602
+ if !stash. contains ( & path) {
1603
+ walk ( & path) ?;
1604
+ }
1599
1605
}
1600
1606
}
1601
1607
0 commit comments