1mod credentials;
2
3pub use credentials::CredentialStore;
4
5use crate::error::{GarminError, Result};
6use std::path::PathBuf;
7
8const CONFIG_DIR_NAME: &str = "garmin";
10
11pub fn config_dir() -> Result<PathBuf> {
14 dirs::config_dir()
15 .map(|p| p.join(CONFIG_DIR_NAME))
16 .ok_or_else(|| GarminError::config("Could not determine config directory"))
17}
18
19pub fn data_dir() -> Result<PathBuf> {
22 dirs::data_dir()
23 .map(|p| p.join(CONFIG_DIR_NAME))
24 .ok_or_else(|| GarminError::config("Could not determine data directory"))
25}
26
27pub fn ensure_dir(path: &PathBuf) -> Result<()> {
29 if !path.exists() {
30 std::fs::create_dir_all(path)?;
31 }
32 Ok(())
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_config_dir_exists() {
41 let dir = config_dir();
42 assert!(dir.is_ok());
43 let path = dir.unwrap();
44 assert!(path.ends_with("garmin"));
45 }
46
47 #[test]
48 fn test_data_dir_exists() {
49 let dir = data_dir();
50 assert!(dir.is_ok());
51 let path = dir.unwrap();
52 assert!(path.ends_with("garmin"));
53 }
54}