Skip to main content

lean_ctx/core/
data_dir.rs

1use std::path::PathBuf;
2
3pub fn lean_ctx_data_dir() -> Result<PathBuf, String> {
4    if let Ok(dir) = std::env::var("LEAN_CTX_DATA_DIR") {
5        let trimmed = dir.trim();
6        if !trimmed.is_empty() {
7            return Ok(PathBuf::from(trimmed));
8        }
9    }
10
11    Ok(dirs::home_dir()
12        .ok_or_else(|| "Cannot determine home directory".to_string())?
13        .join(".lean-ctx"))
14}
15
16pub fn test_env_lock() -> std::sync::MutexGuard<'static, ()> {
17    use std::sync::{Mutex, OnceLock};
18    static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
19    LOCK.get_or_init(|| Mutex::new(())).lock().unwrap()
20}