Creates a new [`ExistingAbsoluteDir`] from `path`. Creates a directory at `path` if it does not exist yet. # Errors Returns an error if - `path` is not absolute, - `path` does not exist and cannot be created, - the metadata of `path` cannot be retrieved, - or `path` is not a directory.
(path: PathBuf)
| 65 | /// - the metadata of `path` cannot be retrieved, |
| 66 | /// - or `path` is not a directory. |
| 67 | pub fn new(path: PathBuf) -> Result<Self, crate::Error> { |
| 68 | if !path.is_absolute() { |
| 69 | return Err(alpm_common::Error::NonAbsolutePaths { |
| 70 | paths: vec![path.clone()], |
| 71 | } |
| 72 | .into()); |
| 73 | } |
| 74 | |
| 75 | if !path.exists() { |
| 76 | create_dir_all(&path).map_err(|source| crate::Error::IoPath { |
| 77 | path: path.clone(), |
| 78 | context: t!("error-io-create-abs-dir"), |
| 79 | source, |
| 80 | })?; |
| 81 | } |
| 82 | |
| 83 | let metadata = path.metadata().map_err(|source| crate::Error::IoPath { |
| 84 | path: path.clone(), |
| 85 | context: t!("error-io-get-metadata"), |
| 86 | source, |
| 87 | })?; |
| 88 | |
| 89 | if !metadata.is_dir() { |
| 90 | return Err(alpm_common::Error::NotADirectory { path: path.clone() }.into()); |
| 91 | } |
| 92 | |
| 93 | Ok(Self(path)) |
| 94 | } |
| 95 | |
| 96 | /// Coerces to a Path slice. |
| 97 | /// |
nothing calls this directly
no test coverage detected