Skip to content

Commit 3d09254

Browse files
authored
Do not show warning if local dir is pointing to global dir. (#2315)
1 parent 3fba9af commit 3d09254

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/soroban-cli/src/config/locator.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ impl Args {
457457
pub fn print_deprecation_warning(dir: &Path) {
458458
let print = Print::new(false);
459459
let global_dir = global_config_path().expect("Couldn't retrieve global directory.");
460+
let global_dir = fs::canonicalize(&global_dir).expect("Couldn't expand global directory.");
461+
462+
// No warning if local and global dirs are the same (e.g., both set to STELLAR_CONFIG_HOME)
463+
if dir == global_dir {
464+
return;
465+
}
460466

461467
print.warnln(format!("A local config was found at {dir:?}."));
462468
print.blankln(" Local config is deprecated and will be removed in the future.".to_string());
@@ -558,6 +564,7 @@ impl KeyType {
558564
pub fn list_paths(&self, paths: &[Location]) -> Result<Vec<(String, Location)>, Error> {
559565
Ok(paths
560566
.iter()
567+
.unique_by(|p| location_to_string(p))
561568
.flat_map(|p| self.list(p, true).unwrap_or_default())
562569
.collect())
563570
}
@@ -662,6 +669,15 @@ fn global_config_path() -> Result<PathBuf, Error> {
662669
Ok(stellar_dir)
663670
}
664671

672+
fn location_to_string(location: &Location) -> String {
673+
match location {
674+
Location::Local(p) | Location::Global(p) => fs::canonicalize(AsRef::<Path>::as_ref(p))
675+
.unwrap_or(p.clone())
676+
.display()
677+
.to_string(),
678+
}
679+
}
680+
665681
// Use locator.global_config_path() to save configurations.
666682
// This is only to be used to fetch global Stellar config (e.g. to use for defaults)
667683
pub fn cli_config_file() -> Result<PathBuf, Error> {

0 commit comments

Comments
 (0)