From 0ee4e2d96f2e6f7cb07faafa9c915e7b731c9e5d Mon Sep 17 00:00:00 2001 From: ducdetronquito Date: Sun, 14 Jan 2024 12:12:43 +0100 Subject: [PATCH] feat: Allow to override data path with BIRTHDAY_DATA environment variable --- src/birthday_store.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/birthday_store.rs b/src/birthday_store.rs index eeed02f..c42676f 100644 --- a/src/birthday_store.rs +++ b/src/birthday_store.rs @@ -19,10 +19,14 @@ pub fn add(name: String, date: String) -> Result<()> { } fn get_db_path() -> Result { - let mut data_dir = match ProjectDirs::from("", "", "birthday") { - Some(project_dirs) => project_dirs.data_dir().to_owned(), - None => Path::new("./").to_owned(), + let mut data_dir = match std::env::var("BIRTHDAY_DATA") { + Ok(path) => PathBuf::from(path), + Err(_) => match ProjectDirs::from("", "", "birthday") { + Some(project_dirs) => project_dirs.data_dir().to_owned(), + None => Path::new("./").to_owned(), + }, }; + std::fs::create_dir_all(&data_dir)?; data_dir.push("test.db"); Ok(data_dir)