Skip to content

Commit 4b81a83

Browse files
committed
Auto merge of #14579 - linyihai:issue-14560, r=epage
fix(config): Don't double-warn about `$CARGO_HOME/config` ### What does this PR try to resolve? The core requirements for this bug are - You have a `$CARGO_HOME/.config` - Your project is inside of `$HOME` We have a check to make sure we don't double-walk `$CARGO/config` but that check is *after* we warn about there being no `.toml` extension. To fix this, we just need to move that check outside of the file lookup. This required changing the `seen` check from checking whether walked the config file to checking if we've walked the config dir. As we only have one file per directory, this should work. Fixes #14560 ### How should we test and review this PR? test commit added the test, fix commit fixed the issue. ### Additional information
2 parents 01e1ab5 + fe917f2 commit 4b81a83

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/cargo/util/context/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1581,20 +1581,21 @@ impl GlobalContext {
15811581
where
15821582
F: FnMut(&Path) -> CargoResult<()>,
15831583
{
1584-
let mut stash: HashSet<PathBuf> = HashSet::new();
1584+
let mut seen_dir = HashSet::new();
15851585

15861586
for current in paths::ancestors(pwd, self.search_stop_path.as_deref()) {
1587-
if let Some(path) = self.get_file_path(&current.join(".cargo"), "config", true)? {
1587+
let config_root = current.join(".cargo");
1588+
if let Some(path) = self.get_file_path(&config_root, "config", true)? {
15881589
walk(&path)?;
1589-
stash.insert(path);
15901590
}
1591+
seen_dir.insert(config_root);
15911592
}
15921593

15931594
// Once we're done, also be sure to walk the home directory even if it's not
15941595
// in our history to be sure we pick up that standard location for
15951596
// information.
1596-
if let Some(path) = self.get_file_path(home, "config", true)? {
1597-
if !stash.contains(&path) {
1597+
if !seen_dir.contains(home) {
1598+
if let Some(path) = self.get_file_path(home, "config", true)? {
15981599
walk(&path)?;
15991600
}
16001601
}

tests/testsuite/config.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use cargo::CargoResult;
1616
use cargo_test_support::compare::assert_e2e;
1717
use cargo_test_support::prelude::*;
1818
use cargo_test_support::str;
19-
use cargo_test_support::{paths, project, symlink_supported, t};
19+
use cargo_test_support::{paths, project, project_in_home, symlink_supported, t};
2020
use cargo_util_schemas::manifest::TomlTrimPaths;
2121
use cargo_util_schemas::manifest::TomlTrimPathsValue;
2222
use cargo_util_schemas::manifest::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB};
@@ -299,6 +299,26 @@ f1 = 1
299299
assert_e2e().eq(&output, expected);
300300
}
301301

302+
#[cargo_test]
303+
fn home_config_works_without_extension() {
304+
write_config_at(
305+
paths::cargo_home().join("config"),
306+
"\
307+
[foo]
308+
f1 = 1
309+
",
310+
);
311+
let p = project_in_home("foo").file("src/lib.rs", "").build();
312+
313+
p.cargo("-vV")
314+
.with_stderr_data(str![[r#"
315+
[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml`
316+
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
317+
318+
"#]])
319+
.run();
320+
}
321+
302322
#[cargo_test]
303323
fn config_ambiguous_filename_symlink_doesnt_warn() {
304324
// Windows requires special permissions to create symlinks.

0 commit comments

Comments
 (0)