From 0bda323c0879b2f1f3f1e16616a8a28436b7d7c7 Mon Sep 17 00:00:00 2001 From: Chris Swindle Date: Mon, 30 Oct 2017 21:25:24 +0000 Subject: [PATCH] Updating based on review comments. --- src/bin/login.rs | 4 ++-- src/cargo/core/source/source_id.rs | 3 +-- src/cargo/ops/registry.rs | 2 +- src/cargo/util/config.rs | 6 ++++-- tests/login.rs | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bin/login.rs b/src/bin/login.rs index a771d7453..499980c6d 100755 --- a/src/bin/login.rs +++ b/src/bin/login.rs @@ -55,8 +55,8 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { Some(token) => token, None => { let host = match options.flag_registry { - Some(ref registry) => { - config.get_registry_index(registry)? + Some(ref _registry) => { + return Err(CargoError::from("token must be provided when --registry is provided.").into()); } None => { let src = SourceId::crates_io(config)?; diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index ed34c95e6..955ecca21 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -183,8 +183,7 @@ impl SourceId { } pub fn alt_registry(config: &Config, key: &str) -> CargoResult { - let index = config.get_registry_index(key)?; - let url = index.to_url()?; + let url = config.get_registry_index(key)?; Ok(SourceId { inner: Arc::new(SourceIdInner { kind: Kind::Registry, diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index bb3d5dda8..5b127c78d 100755 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -196,7 +196,7 @@ pub fn registry_configuration(config: &Config, let (index, token) = match registry { Some(registry) => { - let index = Some(config.get_registry_index(®istry)?); + let index = Some(config.get_registry_index(®istry)?.to_string()); let table = config.get_table(&format!("registry.{}", registry))?.map(|t| t.val); let token = table.and_then(|table| { match table.get("token".into()) { diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 47e79baab..5bf967b1a 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -20,6 +20,8 @@ use toml; use core::shell::Verbosity; use core::{Shell, CliUnstable}; use ops; +use url::Url; +use util::ToUrl; use util::Rustc; use util::errors::{CargoResult, CargoResultExt, CargoError, internal}; use util::paths; @@ -546,9 +548,9 @@ impl Config { } /// Gets the index for a registry. - pub fn get_registry_index(&self, registry: &str) -> CargoResult { + pub fn get_registry_index(&self, registry: &str) -> CargoResult { Ok(match self.get_string(&format!("registries.{}.index", registry))? { - Some(index) => index.val, + Some(index) => index.val.to_url()?, None => return Err(CargoError::from(format!("No index found for registry: `{}`", registry)).into()), }) } diff --git a/tests/login.rs b/tests/login.rs index b35c72a61..9aa356408 100755 --- a/tests/login.rs +++ b/tests/login.rs @@ -22,10 +22,10 @@ const CONFIG_FILE: &str = r#" token = "api-token" [registries.test-reg] - index = "dummy_index" + index = "http://dummy_index/" [registries.test.reg] - index = "dummy_index" + index = "http://dummy_index/" "#; fn setup_old_credentials() {