@@ -662,7 +662,7 @@ impl Config {
662
662
let mut cfg = CV :: Table ( HashMap :: new ( ) , PathBuf :: from ( "." ) ) ;
663
663
let home = self . home_path . clone ( ) . into_path_unlocked ( ) ;
664
664
665
- walk_tree ( path, & home, |path| {
665
+ self . walk_tree ( path, & home, |path| {
666
666
let mut contents = String :: new ( ) ;
667
667
let mut file = File :: open ( & path) ?;
668
668
file. read_to_string ( & mut contents)
@@ -689,6 +689,61 @@ impl Config {
689
689
}
690
690
}
691
691
692
+ fn walk_tree < F > ( & self , pwd : & Path , home : & Path , mut walk : F ) -> CargoResult < ( ) >
693
+ where
694
+ F : FnMut ( & Path ) -> CargoResult < ( ) > ,
695
+ {
696
+ let mut stash: HashSet < PathBuf > = HashSet :: new ( ) ;
697
+
698
+ for current in paths:: ancestors ( pwd) {
699
+ let possible = current. join ( ".cargo" ) . join ( "config" ) ;
700
+ let possible_with_extension = current. join ( ".cargo" ) . join ( "config.toml" ) ;
701
+
702
+ // If both 'config' and 'config.toml' exist, we should use 'config'
703
+ // for backward compatibility, but we should warn the user.
704
+ if fs:: metadata ( & possible) . is_ok ( ) {
705
+ if fs:: metadata ( & possible_with_extension) . is_ok ( ) {
706
+ self . shell ( ) . warn ( format ! (
707
+ "Both `{}` and `{}` exist. Using `{}`" ,
708
+ possible. display( ) ,
709
+ possible_with_extension. display( ) ,
710
+ possible. display( )
711
+ ) ) ?;
712
+ }
713
+
714
+ walk ( & possible) ?;
715
+ stash. insert ( possible) ;
716
+ } else if fs:: metadata ( & possible_with_extension) . is_ok ( ) {
717
+ walk ( & possible_with_extension) ?;
718
+ stash. insert ( possible) ;
719
+ }
720
+ }
721
+
722
+ // Once we're done, also be sure to walk the home directory even if it's not
723
+ // in our history to be sure we pick up that standard location for
724
+ // information.
725
+ let config = home. join ( "config" ) ;
726
+ let config_with_extension = home. join ( "config.toml" ) ;
727
+ if !stash. contains ( & config) && fs:: metadata ( & config) . is_ok ( ) {
728
+ if fs:: metadata ( & config_with_extension) . is_ok ( ) {
729
+ self . shell ( ) . warn ( format ! (
730
+ "Both `{}` and `{}` exist. Using `{}`" ,
731
+ config. display( ) ,
732
+ config_with_extension. display( ) ,
733
+ config. display( )
734
+ ) ) ?;
735
+ }
736
+
737
+ walk ( & config) ?;
738
+ } else if !stash. contains ( & config_with_extension)
739
+ && fs:: metadata ( & config_with_extension) . is_ok ( )
740
+ {
741
+ walk ( & config_with_extension) ?;
742
+ }
743
+
744
+ Ok ( ( ) )
745
+ }
746
+
692
747
/// Gets the index for a registry.
693
748
pub fn get_registry_index ( & self , registry : & str ) -> CargoResult < Url > {
694
749
validate_package_name ( registry, "registry name" , "" ) ?;
@@ -1673,31 +1728,6 @@ pub fn homedir(cwd: &Path) -> Option<PathBuf> {
1673
1728
:: home:: cargo_home_with_cwd ( cwd) . ok ( )
1674
1729
}
1675
1730
1676
- fn walk_tree < F > ( pwd : & Path , home : & Path , mut walk : F ) -> CargoResult < ( ) >
1677
- where
1678
- F : FnMut ( & Path ) -> CargoResult < ( ) > ,
1679
- {
1680
- let mut stash: HashSet < PathBuf > = HashSet :: new ( ) ;
1681
-
1682
- for current in paths:: ancestors ( pwd) {
1683
- let possible = current. join ( ".cargo" ) . join ( "config" ) ;
1684
- if fs:: metadata ( & possible) . is_ok ( ) {
1685
- walk ( & possible) ?;
1686
- stash. insert ( possible) ;
1687
- }
1688
- }
1689
-
1690
- // Once we're done, also be sure to walk the home directory even if it's not
1691
- // in our history to be sure we pick up that standard location for
1692
- // information.
1693
- let config = home. join ( "config" ) ;
1694
- if !stash. contains ( & config) && fs:: metadata ( & config) . is_ok ( ) {
1695
- walk ( & config) ?;
1696
- }
1697
-
1698
- Ok ( ( ) )
1699
- }
1700
-
1701
1731
pub fn save_credentials ( cfg : & Config , token : String , registry : Option < String > ) -> CargoResult < ( ) > {
1702
1732
let mut file = {
1703
1733
cfg. home_path . create_dir ( ) ?;
0 commit comments