Strata/strata-daemon/src/config.rs
edu4rdshl 8d681a16fd fix: panic with clear message if XDG data dir is unavailable
The previous fallback to PathBuf::from(".") silently placed the
database in whatever the current working directory was, making it
impossible to find later. Since the daemon cannot function without a
persistent database, failing fast with an actionable message is the
correct behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-25 03:43:52 -05:00

26 lines
631 B
Rust

use std::path::PathBuf;
pub struct Config {
pub db_path: PathBuf,
pub max_history: usize,
}
impl Config {
pub fn new() -> Self {
let data_dir = dirs::data_dir()
.expect(
"Could not determine XDG data directory. \
Ensure $XDG_DATA_HOME or $HOME is set.",
)
.join("strata");
if let Err(e) = std::fs::create_dir_all(&data_dir) {
tracing::warn!("Could not create data dir {:?}: {}", data_dir, e);
}
Self {
db_path: data_dir.join("clipboard.db"),
max_history: 200,
}
}
}