simple_fs/common/
system.rs1use crate::{Error, Result, SPath};
2use std::path::Path;
3
4pub fn home_dir() -> Result<SPath> {
6 let path = std::env::home_dir().ok_or(Error::HomeDirNotFound)?;
7 SPath::from_std_path(path)
8}
9
10pub fn current_dir() -> Result<SPath> {
12 let path = std::env::current_dir().map_err(|e| Error::FileCantRead((Path::new("."), e).into()))?;
13 SPath::from_std_path_buf(path)
14}
15
16#[cfg(test)]
19mod tests {
20 type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
21
22 use super::*;
23
24 #[test]
25 fn test_common_system_home_dir_simple() -> Result<()> {
26 let home = home_dir()?;
28
29 assert!(home.exists(), "Home directory should exist");
31 assert!(home.is_absolute(), "Home directory should be an absolute path");
32
33 Ok(())
34 }
35
36 #[test]
37 fn test_common_system_current_dir_simple() -> Result<()> {
38 let current = current_dir()?;
40
41 assert!(current.exists(), "Current directory should exist");
43 assert!(current.is_absolute(), "Current directory should be an absolute path");
44
45 Ok(())
46 }
47}
48
49