diff --git a/src/cargo/sources/registry.rs b/src/cargo/sources/registry.rs index 94bfa7d4ee2..a4ea34955dc 100644 --- a/src/cargo/sources/registry.rs +++ b/src/cargo/sources/registry.rs @@ -174,7 +174,7 @@ use url::Url; use core::{Source, SourceId, PackageId, Package, Summary, Registry}; use core::dependency::{Dependency, DependencyInner, Kind}; use sources::{PathSource, git}; -use util::{CargoResult, Config, internal, ChainError, ToUrl, human}; +use util::{CargoResult, Config, internal, ChainError, ToUrl, ToUrlWithBase, human}; use util::{hex, Sha256, paths}; use ops; @@ -251,9 +251,12 @@ impl<'cfg> RegistrySource<'cfg> { /// This is the main cargo registry by default, but it can be overridden in /// a .cargo/config pub fn url(config: &Config) -> CargoResult { - let config = try!(ops::registry_configuration(config)); - let url = config.index.unwrap_or(DEFAULT.to_string()); - url.to_url().map_err(human) + let result = match try!(config.get_string("registry.index")) { + Some((value, path)) => value.to_url_with_base(path.as_path().clone()), + None => DEFAULT.to_string().to_url(), + }; + + Ok(try!(result.map_err(human))) } /// Get the default url for the registry diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index 49963201d92..bdf0dfea2b9 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -14,7 +14,7 @@ pub use self::process_builder::{process, ProcessBuilder}; pub use self::rustc::Rustc; pub use self::sha256::Sha256; pub use self::to_semver::ToSemver; -pub use self::to_url::ToUrl; +pub use self::to_url::{ToUrl, ToUrlWithBase}; pub use self::vcs::{GitRepo, HgRepo}; pub mod config; diff --git a/src/cargo/util/to_url.rs b/src/cargo/util/to_url.rs index 2e3365cb255..370000d8f59 100644 --- a/src/cargo/util/to_url.rs +++ b/src/cargo/util/to_url.rs @@ -5,6 +5,10 @@ pub trait ToUrl { fn to_url(self) -> Result; } +pub trait ToUrlWithBase { + fn to_url_with_base(self, base: U) -> Result; +} + impl ToUrl for Url { fn to_url(self) -> Result { Ok(self) @@ -25,6 +29,22 @@ impl<'a> ToUrl for &'a str { } } +impl<'a> ToUrlWithBase for &'a str { + fn to_url_with_base(self, base: U) -> Result { + let base_url: Result = base.to_url().map_err(|s| { + format!("invalid url `{}`: {}", self, s) + }); + let base_url = try!(base_url); + + UrlParser::new() + .scheme_type_mapper(mapper) + .base_url(&base_url) + .parse(self).map_err(|s| { + format!("invalid url `{}`: {}", self, s) + }) + } +} + impl<'a> ToUrl for &'a Path { fn to_url(self) -> Result { Url::from_file_path(self).map_err(|()| {