use std::path::PathBuf;
pub fn home_dir() -> std::io::Result<PathBuf> {
if let Ok(p) = std::env::var("OXI_HOME") {
if !p.is_empty() {
return Ok(PathBuf::from(p));
}
}
let home = dirs::home_dir()
.ok_or_else(|| std::io::Error::new(std::io::ErrorKind::NotFound, "HOME not set"))?;
Ok(home.join(".oxi"))
}
pub async fn ensure_dir(path: &std::path::Path) -> std::io::Result<()> {
if !path.exists() {
tokio::fs::create_dir_all(path).await?;
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn home_dir_resolves() {
let d = home_dir();
if std::env::var("OXI_HOME").is_err() && dirs::home_dir().is_none() {
assert!(d.is_err());
} else {
assert!(d.is_ok());
}
}
}