From 8096fde8d98cdde4e110865ebb15ad034b92ff27 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 14:15:23 +0000 Subject: config: the root is the directory config.json lives in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `--root` names a directory and `init` writes config.json inside it, so the root was already named by where the config lived. The `root` field in the file was treated as a second source of truth instead: a relative one was re-joined onto the config's own directory, and `init` saved whatever it had been handed. So `--root runtime` wrote `"root": "runtime"`, and every command after `init` resolved it to `runtime/runtime/` — a second tree with its own empty database, while `init` had created and migrated the first one. The user-visible half was a path like `runtime/runtime/repo/aur-build/os/x86_64/…` in an error message. Compounding it, the CLI fell back to a default config whenever loading failed, so a typo'd `--root` produced a fresh empty server that answered every command as though it were the one you meant. `load` now sets the root to the directory it found the config in, absolutized, and a missing config is an error for every command except `init` — the only one that runs before one exists. --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 91c086b..9e3b1e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,12 +118,19 @@ enum Cmd { fn main() -> anyhow::Result<()> { let cli = Cli::parse(); - let cfg = match &cli.root { - Some(r) => Config::load(r).unwrap_or_else(|_| Config { - root: r.clone(), + // `init` is the only command that runs before a config exists. For everything + // else a missing config is the error it sounds like, not a reason to invent + // one: the old unconditional fallback turned a typo'd `--root` into a fresh + // empty server at the wrong path, whose commands then "succeeded" against a + // database with no subscriptions and no releases in it. + let root = cli.root.clone().unwrap_or_else(|| Config::default().root); + let cfg = if matches!(cli.cmd, Cmd::Init { .. }) { + Config::load(&root).unwrap_or_else(|_| Config { + root: root.clone(), ..Config::default() - }), - None => Config::load(&Config::default().root)?, + }) + } else { + Config::load(&root)? }; if let Cmd::Serve { bind } = &cli.cmd { let mut cfg = cfg; -- cgit v1.2.3