diff --git a/src/tools.rs b/src/tools.rs index 0696d3b0..fd48c535 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -165,8 +165,8 @@ pub fn file_set_contents_full>( path: P, data: &[u8], perm: Option, - owner: Option, - group: Option, + owner: Option, + group: Option, ) -> Result<(), Error> { let path = path.as_ref(); @@ -351,6 +351,26 @@ pub fn getpwnam_ugid(username: &str) -> Result<(libc::uid_t,libc::gid_t), Error> Ok((info.pw_uid, info.pw_gid)) } +/// Creates a new, empty directory at the provided path witzh specified ownership +pub fn create_dir_chown>( + path: P, + perm: Option, + owner: Option, + group: Option, +) -> Result<(), Error> +{ + let mode : stat::Mode = perm.unwrap_or(stat::Mode::from( + stat::Mode::S_IRWXO | stat::Mode::S_IRWXG + )); + + let path = path.as_ref(); + + unistd::mkdir(path, mode)?; + unistd::chown(path, owner, group)?; + + Ok(()) +} + /// Change ownership of an open file handle pub fn fchown( fd: RawFd,