Skip to content

Commit

Permalink
fix(config): Don't double-warn about $CARGO_HOME/config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
epage committed Sep 25, 2024
1 parent 0b83e92 commit fe917f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,20 +1581,21 @@ impl GlobalContext {
where
F: FnMut(&Path) -> CargoResult<()>,
{
let mut seen = HashSet::new();
let mut seen_dir = HashSet::new();

for current in paths::ancestors(pwd, self.search_stop_path.as_deref()) {
if let Some(path) = self.get_file_path(&current.join(".cargo"), "config", true)? {
let config_root = current.join(".cargo");
if let Some(path) = self.get_file_path(&config_root, "config", true)? {
walk(&path)?;
seen.insert(path);
}
seen_dir.insert(config_root);
}

// Once we're done, also be sure to walk the home directory even if it's not
// in our history to be sure we pick up that standard location for
// information.
if let Some(path) = self.get_file_path(home, "config", true)? {
if !seen.contains(&path) {
if !seen_dir.contains(home) {
if let Some(path) = self.get_file_path(home, "config", true)? {
walk(&path)?;
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ f1 = 1
.with_stderr_data(str![[r#"
[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml`
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml`
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
"#]])
.run();
Expand Down

0 comments on commit fe917f2

Please sign in to comment.