diff --git a/src/config.rs b/src/config.rs index 75cc5d0..6293ec8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -924,14 +924,23 @@ impl Default for Config { } /// Where the config lives when `--config` is not given. -/// Repo checkout (`config/gateway.toml` exists or `config/` dir exists) → keep it there; -/// installed binary (no repo) → `$data_dir/gateway.toml`. +/// A readable `./config/gateway.toml` (a real gateway checkout / install dir) +/// wins; otherwise the per-user home (`$CORTIQ_GATEWAY_HOME` or +/// `~/.cortiq-gateway`) — so `cortiq-gateway` typed in any directory picks up +/// the same configuration it was set up with. A foreign project that merely +/// has `Cargo.toml` and a `config/` folder must NOT capture the config +/// (that used to shadow the user's real config with a broken path). pub fn default_config_path() -> String { let repo_path = "config/gateway.toml"; - if std::path::Path::new(repo_path).exists() { + // the file itself, readable — not just an entry that exists() + if std::fs::read_to_string(repo_path).is_ok() { return repo_path.to_string(); } - if std::path::Path::new("Cargo.toml").exists() && std::path::Path::new("config").exists() { + // our own repo checkout before first run: config/ exists, file not yet + let ours = std::fs::read_to_string("Cargo.toml") + .map(|t| t.contains("name = \"cortiq-gateway\"")) + .unwrap_or(false); + if ours && std::path::Path::new("config").is_dir() { return repo_path.to_string(); } data_dir()