feat(paths): auto-create config dir on daemon startup
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user