fix(config): a foreign project must not capture the config path
default_config_path treated any directory holding Cargo.toml plus a config/ folder as a gateway checkout, so running cortiq-gateway inside an unrelated project died with "cannot read config config/gateway.toml" instead of using the per-user home. Now ./config/gateway.toml counts only when the file is actually readable, the repo-checkout heuristic requires Cargo.toml to be cortiq-gateway's own, and everything else falls through to $CORTIQ_GATEWAY_HOME / ~/.cortiq-gateway — typing cortiq-gateway in any directory picks up the same configuration.
This commit is contained in:
+13
-4
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user