From 00c7e7e8126e6d6fcd24d28a5d8524039ff350f0 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Tue, 26 May 2026 12:44:47 +0200 Subject: [PATCH] feat(paths): auto-create config dir on daemon startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ensure_dirs() now creates config_dir alongside state_dir and log_dir, so first daemon run materializes $XDG_CONFIG_HOME/xy/servers/ — making it obvious where to drop server .kdl files. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/xy/src/paths.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/xy/src/paths.rs b/crates/xy/src/paths.rs index fef2d81..b605af7 100644 --- a/crates/xy/src/paths.rs +++ b/crates/xy/src/paths.rs @@ -30,6 +30,7 @@ impl Paths { } pub fn ensure_dirs(&self) -> std::io::Result<()> { + std::fs::create_dir_all(&self.config_dir)?; std::fs::create_dir_all(&self.state_dir)?; std::fs::create_dir_all(&self.log_dir)?; Ok(()) @@ -45,4 +46,24 @@ mod tests { let p = Paths::resolve().unwrap(); assert!(p.pidfile.starts_with(&p.state_dir)); } + + #[test] + fn ensure_dirs_creates_all_paths() { + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path(); + + let paths = Paths { + config_dir: root.join("config/xy/servers"), + state_dir: root.join("state/xy"), + log_dir: root.join("state/xy/logs"), + socket: root.join("run/xy.sock"), + pidfile: root.join("state/xy/xy.pid"), + }; + + paths.ensure_dirs().unwrap(); + + assert!(paths.config_dir.is_dir()); + assert!(paths.state_dir.is_dir()); + assert!(paths.log_dir.is_dir()); + } }