Skip to content

Commit 9d00f9f

Browse files
committed
Make setting registry.index a hard error.
This has been deprecated for 4 years. This helps simplify this code.
1 parent 7956f03 commit 9d00f9f

File tree

6 files changed

+66
-107
lines changed

6 files changed

+66
-107
lines changed

src/cargo/core/source/source_id.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use std::fmt::{self, Formatter};
44
use std::hash::{self, Hash};
55
use std::path::Path;
66
use std::ptr;
7-
use std::sync::atomic::AtomicBool;
8-
use std::sync::atomic::Ordering::SeqCst;
97
use std::sync::Mutex;
108

119
use log::trace;
@@ -14,7 +12,6 @@ use serde::ser;
1412
use url::Url;
1513

1614
use crate::core::PackageId;
17-
use crate::ops;
1815
use crate::sources::DirectorySource;
1916
use crate::sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX};
2017
use crate::util::{CanonicalUrl, CargoResult, Config, IntoUrl};
@@ -189,22 +186,8 @@ impl SourceId {
189186
/// a `.cargo/config`.
190187
pub fn crates_io(config: &Config) -> CargoResult<SourceId> {
191188
config.crates_io_source_id(|| {
192-
let cfg = ops::registry_configuration(config, None)?;
193-
let url = if let Some(ref index) = cfg.index {
194-
static WARNED: AtomicBool = AtomicBool::new(false);
195-
if !WARNED.swap(true, SeqCst) {
196-
config.shell().warn(
197-
"custom registry support via \
198-
the `registry.index` configuration is \
199-
being removed, this functionality \
200-
will not work in the future",
201-
)?;
202-
}
203-
&index[..]
204-
} else {
205-
CRATES_IO_INDEX
206-
};
207-
let url = url.into_url()?;
189+
config.check_registry_index_not_set()?;
190+
let url = CRATES_IO_INDEX.into_url().unwrap();
208191
SourceId::for_registry(&url)
209192
})
210193
}

src/cargo/ops/registry.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ fn transmit(
324324
/// Returns the index and token from the config file for the given registry.
325325
///
326326
/// `registry` is typically the registry specified on the command-line. If
327-
/// `None`, returns the default index.
327+
/// `None`, `index` is set to `None` to indicate it should use crates.io.
328328
pub fn registry_configuration(
329329
config: &Config,
330330
registry: Option<String>,
@@ -341,13 +341,9 @@ pub fn registry_configuration(
341341
)
342342
}
343343
None => {
344-
// Checking for default index and token
345-
(
346-
config
347-
.get_default_registry_index()?
348-
.map(|url| url.to_string()),
349-
config.get_string("registry.token")?.map(|p| p.val),
350-
)
344+
// Use crates.io default.
345+
config.check_registry_index_not_set()?;
346+
(None, config.get_string("registry.token")?.map(|p| p.val))
351347
}
352348
};
353349

src/cargo/util/config/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,12 +1016,15 @@ impl Config {
10161016
)
10171017
}
10181018

1019-
/// Gets the index for the default registry.
1020-
pub fn get_default_registry_index(&self) -> CargoResult<Option<Url>> {
1021-
Ok(match self.get_string("registry.index")? {
1022-
Some(index) => Some(self.resolve_registry_index(index)?),
1023-
None => None,
1024-
})
1019+
/// Returns an error if `registry.index` is set.
1020+
pub fn check_registry_index_not_set(&self) -> CargoResult<()> {
1021+
if self.get_string("registry.index")?.is_some() {
1022+
bail!(
1023+
"the `registry.index` config value is no longer supported\n\
1024+
Use `[source]` replacement to alter the default index for crates.io."
1025+
);
1026+
}
1027+
Ok(())
10251028
}
10261029

10271030
fn resolve_registry_index(&self, index: Value<String>) -> CargoResult<Url> {

src/doc/src/reference/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ specified.
686686

687687
##### `registry.index`
688688

689-
This value is deprecated and should not be used.
689+
This value is no longer accepted and should not be used.
690690

691691
##### `registry.default`
692692
* Type: string

tests/testsuite/alt_registry.rs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -528,28 +528,6 @@ fn publish_with_crates_io_dep() {
528528
);
529529
}
530530

531-
#[cargo_test]
532-
fn passwords_in_registry_index_url_forbidden() {
533-
registry::init();
534-
535-
let config = paths::home().join(".cargo/config");
536-
fs::write(
537-
config,
538-
r#"
539-
[registry]
540-
index = "ssh://git:[email protected]"
541-
"#,
542-
)
543-
.unwrap();
544-
545-
let p = project().file("src/main.rs", "fn main() {}").build();
546-
547-
p.cargo("publish")
548-
.with_status(101)
549-
.with_stderr_contains("error: Registry URLs may not contain passwords")
550-
.run();
551-
}
552-
553531
#[cargo_test]
554532
fn passwords_in_registries_index_url_forbidden() {
555533
registry::init();
@@ -1222,57 +1200,6 @@ fn registries_index_relative_url() {
12221200
.run();
12231201
}
12241202

1225-
#[cargo_test]
1226-
fn registry_index_relative_url() {
1227-
let config = paths::root().join(".cargo/config");
1228-
fs::create_dir_all(config.parent().unwrap()).unwrap();
1229-
fs::write(
1230-
&config,
1231-
r#"
1232-
[registry]
1233-
index = "file:alternative-registry"
1234-
"#,
1235-
)
1236-
.unwrap();
1237-
1238-
registry::init();
1239-
1240-
let p = project()
1241-
.file(
1242-
"Cargo.toml",
1243-
r#"
1244-
[project]
1245-
name = "foo"
1246-
version = "0.0.1"
1247-
authors = []
1248-
1249-
[dependencies.bar]
1250-
version = "0.0.1"
1251-
"#,
1252-
)
1253-
.file("src/main.rs", "fn main() {}")
1254-
.build();
1255-
1256-
Package::new("bar", "0.0.1").alternative(true).publish();
1257-
1258-
fs::remove_file(paths::home().join(".cargo/config")).unwrap();
1259-
1260-
p.cargo("build")
1261-
.with_stderr(&format!(
1262-
"\
1263-
warning: custom registry support via the `registry.index` configuration is being removed, this functionality will not work in the future
1264-
[UPDATING] `{reg}` index
1265-
[DOWNLOADING] crates ...
1266-
[DOWNLOADED] bar v0.0.1 (registry `[ROOT][..]`)
1267-
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
1268-
[COMPILING] foo v0.0.1 ([CWD])
1269-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
1270-
",
1271-
reg = registry::alt_registry_path().to_str().unwrap()
1272-
))
1273-
.run();
1274-
}
1275-
12761203
#[cargo_test]
12771204
fn registries_index_relative_path_not_allowed() {
12781205
let config = paths::root().join(".cargo/config");

tests/testsuite/registry.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,3 +2079,53 @@ fn readonly_registry_still_works() {
20792079
t!(fs::set_permissions(path, perms));
20802080
}
20812081
}
2082+
2083+
#[cargo_test]
2084+
fn registry_index_rejected() {
2085+
Package::new("dep", "0.1.0").publish();
2086+
2087+
let p = project()
2088+
.file(
2089+
".cargo/config",
2090+
r#"
2091+
[registry]
2092+
index = "https://example.com/"
2093+
"#,
2094+
)
2095+
.file(
2096+
"Cargo.toml",
2097+
r#"
2098+
[package]
2099+
name = "foo"
2100+
version = "0.1.0"
2101+
2102+
[dependencies]
2103+
dep = "0.1"
2104+
"#,
2105+
)
2106+
.file("src/lib.rs", "")
2107+
.build();
2108+
2109+
p.cargo("check")
2110+
.with_status(101)
2111+
.with_stderr(
2112+
"\
2113+
[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
2114+
2115+
Caused by:
2116+
the `registry.index` config value is no longer supported
2117+
Use `[source]` replacement to alter the default index for crates.io.
2118+
",
2119+
)
2120+
.run();
2121+
2122+
p.cargo("login")
2123+
.with_status(101)
2124+
.with_stderr(
2125+
"\
2126+
[ERROR] the `registry.index` config value is no longer supported
2127+
Use `[source]` replacement to alter the default index for crates.io.
2128+
",
2129+
)
2130+
.run();
2131+
}

0 commit comments

Comments
 (0)