src/tools.rs: implement create_dir_chown

Combinded mkdir with chown.
This commit is contained in:
Dietmar Maurer 2019-04-06 16:50:23 +02:00
parent eea8131952
commit 1619a72063

View File

@ -165,8 +165,8 @@ pub fn file_set_contents_full<P: AsRef<Path>>(
path: P,
data: &[u8],
perm: Option<stat::Mode>,
owner: Option<nix::unistd::Uid>,
group: Option<nix::unistd::Gid>,
owner: Option<unistd::Uid>,
group: Option<unistd::Gid>,
) -> 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<P: AsRef<Path>>(
path: P,
perm: Option<stat::Mode>,
owner: Option<unistd::Uid>,
group: Option<unistd::Gid>,
) -> 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,