@@ -29,7 +29,7 @@ use crate::util::errors::{self, internal, CargoResult, CargoResultExt};
29
29
use crate :: util:: toml as cargo_toml;
30
30
use crate :: util:: Filesystem ;
31
31
use crate :: util:: Rustc ;
32
- use crate :: util:: ToUrl ;
32
+ use crate :: util:: ToUrlWithBase ;
33
33
use crate :: util:: { paths, validate_package_name} ;
34
34
35
35
/// Configuration information for cargo. This is not specific to a build, it is information
@@ -667,18 +667,31 @@ impl Config {
667
667
validate_package_name ( registry, "registry name" , "" ) ?;
668
668
Ok (
669
669
match self . get_string ( & format ! ( "registries.{}.index" , registry) ) ? {
670
- Some ( index) => {
671
- let url = index. val . to_url ( ) ?;
672
- if url. password ( ) . is_some ( ) {
673
- failure:: bail!( "Registry URLs may not contain passwords" ) ;
674
- }
675
- url
676
- }
670
+ Some ( index) => self . resolve_registry_index ( index) ?,
677
671
None => failure:: bail!( "No index found for registry: `{}`" , registry) ,
678
672
} ,
679
673
)
680
674
}
681
675
676
+ /// Gets the index for the default registry.
677
+ pub fn get_default_registry_index ( & self ) -> CargoResult < Option < Url > > {
678
+ Ok (
679
+ match self . get_string ( "registry.index" ) ? {
680
+ Some ( index) => Some ( self . resolve_registry_index ( index) ?) ,
681
+ None => None ,
682
+ } ,
683
+ )
684
+ }
685
+
686
+ fn resolve_registry_index ( & self , index : Value < String > ) -> CargoResult < Url > {
687
+ let base = index. definition . root ( & self ) ;
688
+ let url = index. val . to_url_with_base ( Some ( base) ) ?;
689
+ if url. password ( ) . is_some ( ) {
690
+ failure:: bail!( "Registry URLs may not contain passwords" ) ;
691
+ }
692
+ Ok ( url)
693
+ }
694
+
682
695
/// Loads credentials config from the credentials file into the `ConfigValue` object, if
683
696
/// present.
684
697
fn load_credentials ( & self , cfg : & mut ConfigValue ) -> CargoResult < ( ) > {
@@ -1648,3 +1661,4 @@ pub fn save_credentials(cfg: &Config, token: String, registry: Option<String>) -
1648
1661
Ok ( ( ) )
1649
1662
}
1650
1663
}
1664
+
0 commit comments