use crate::{Error, Result, SPath};
use std::path::Path;
pub fn home_dir() -> Result<SPath> {
let path = std::env::home_dir().ok_or(Error::HomeDirNotFound)?;
SPath::from_std_path(path)
}
pub fn current_dir() -> Result<SPath> {
let path = std::env::current_dir().map_err(|e| Error::FileCantRead((Path::new("."), e).into()))?;
SPath::from_std_path_buf(path)
}
#[cfg(test)]
mod tests {
type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
use super::*;
#[test]
fn test_common_system_home_dir_simple() -> Result<()> {
let home = home_dir()?;
assert!(home.exists(), "Home directory should exist");
assert!(home.is_absolute(), "Home directory should be an absolute path");
Ok(())
}
#[test]
fn test_common_system_current_dir_simple() -> Result<()> {
let current = current_dir()?;
assert!(current.exists(), "Current directory should exist");
assert!(current.is_absolute(), "Current directory should be an absolute path");
Ok(())
}
}