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

Method new

alpm-package/src/config.rs:37–68  ·  view source on GitHub ↗

Creates a new [`OutputDir`] from `path`. Creates a directory at `path` if it does not exist yet. Also creates any missing parent directories. # Errors Returns an error if - `path` is not absolute, - `path` does not exist and cannot be created, - the metadata of `path` cannot be retrieved, - `path` is not a directory, - or `path` is only read-only.

(path: PathBuf)

Source from the content-addressed store, hash-verified

35 /// - `path` is not a directory,
36 /// - or `path` is only read-only.
37 pub fn new(path: PathBuf) -> Result<Self, crate::Error> {
38 if !path.is_absolute() {
39 return Err(alpm_common::Error::NonAbsolutePaths {
40 paths: vec![path.clone()],
41 }
42 .into());
43 }
44
45 if !path.exists() {
46 create_dir_all(&path).map_err(|source| crate::Error::IoPath {
47 path: path.clone(),
48 context: t!("error-io-create-output-dir"),
49 source,
50 })?;
51 }
52
53 let metadata = path.metadata().map_err(|source| crate::Error::IoPath {
54 path: path.clone(),
55 context: t!("error-io-get-metadata"),
56 source,
57 })?;
58
59 if !metadata.is_dir() {
60 return Err(alpm_common::Error::NotADirectory { path: path.clone() }.into());
61 }
62
63 if metadata.permissions().readonly() {
64 return Err(crate::Error::PathIsReadOnly { path: path.clone() });
65 }
66
67 Ok(Self(path))
68 }
69
70 /// Coerces to a Path slice.
71 pub fn as_path(&self) -> &Path {

Callers

nothing calls this directly

Calls 6

metadataMethod · 0.80
is_dirMethod · 0.80
permissionsMethod · 0.80
input_dirMethod · 0.80
as_pathMethod · 0.45
to_path_bufMethod · 0.45

Tested by

no test coverage detected