MCPcopy Create free account
hub / github.com/archlinux/alpm / new

Method new

alpm-package/src/package.rs:67–94  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 ///

Callers

nothing calls this directly

Calls 5

metadataMethod · 0.80
is_dirMethod · 0.80
is_fileMethod · 0.80
joinMethod · 0.45
to_path_bufMethod · 0.45

Tested by

no test coverage detected