Skip to content

Commit 259f72d

Browse files
committed
fix: Avoid walking config twice
1 parent 6628a6e commit 259f72d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/cargo/util/context/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1577,25 +1577,27 @@ impl GlobalContext {
15771577
}
15781578
}
15791579

1580-
fn walk_tree<F>(&self, pwd: &Path, home: &Path, mut walk: F) -> CargoResult<()>
1580+
fn walk_tree<F>(&self, pwd: &Path, cargo_home: &Path, mut walk: F) -> CargoResult<()>
15811581
where
15821582
F: FnMut(&Path) -> CargoResult<()>,
15831583
{
15841584
let mut stash: HashSet<PathBuf> = HashSet::new();
15851585

15861586
for current in paths::ancestors(pwd, self.search_stop_path.as_deref()) {
1587+
// Be aware `current` may be the parent of the `$CARGO_HOME`, in this case the next line also walk the `$CARGO_HOME`.
15871588
if let Some(path) = self.get_file_path(&current.join(".cargo"), "config", true)? {
15881589
walk(&path)?;
15891590
stash.insert(path);
15901591
}
15911592
}
15921593

1593-
// Once we're done, also be sure to walk the home directory even if it's not
1594-
// in our history to be sure we pick up that standard location for
1595-
// information.
1596-
if let Some(path) = self.get_file_path(home, "config", true)? {
1597-
if !stash.contains(&path) {
1598-
walk(&path)?;
1594+
let cargo_home_parent = cargo_home.parent().unwrap_or(cargo_home);
1595+
// If we haven't walked the $CARGO_HOME directory yet, walk it to pick up that standard location for information.
1596+
if !pwd.starts_with(cargo_home_parent) {
1597+
if let Some(path) = self.get_file_path(cargo_home, "config", true)? {
1598+
if !stash.contains(&path) {
1599+
walk(&path)?;
1600+
}
15991601
}
16001602
}
16011603

tests/testsuite/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ f1 = 1
315315
.with_stderr_data(str![[r#"
316316
[WARNING] `[ROOT]/.cargo/config` is deprecated in favor of `config.toml`
317317
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
318-
[WARNING] `[ROOT]/.cargo/config` is deprecated in favor of `config.toml`
319-
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
320318
321319
"#]])
322320
.run();

0 commit comments

Comments
 (0)