From 6bb932e604bd4d67b75dd4243d30af41fa34ac7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Thu, 2 Dec 2021 09:02:24 +0100 Subject: [PATCH] use nix::unistd::fchown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instead of re-implementing it, now that we depend on >=0.19 Signed-off-by: Fabian Grünbichler --- proxmox-sys/src/fs/mod.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/proxmox-sys/src/fs/mod.rs b/proxmox-sys/src/fs/mod.rs index bf037c77..9fe333b9 100644 --- a/proxmox-sys/src/fs/mod.rs +++ b/proxmox-sys/src/fs/mod.rs @@ -7,7 +7,6 @@ use anyhow::{bail, Error}; use std::os::unix::io::{AsRawFd, RawFd}; use nix::unistd::{Gid, Uid}; use nix::sys::stat; -use nix::errno::Errno; pub mod acl; @@ -27,16 +26,7 @@ pub mod xattr; /// Change ownership of an open file handle pub fn fchown(fd: RawFd, owner: Option, group: Option) -> Result<(), Error> { - // According to the POSIX specification, -1 is used to indicate that owner and group - // are not to be changed. Since uid_t and gid_t are unsigned types, we have to wrap - // around to get -1 (copied fron nix crate). - let uid = owner.map(Into::into).unwrap_or(!(0 as libc::uid_t)); - let gid = group.map(Into::into).unwrap_or(!(0 as libc::gid_t)); - - let res = unsafe { libc::fchown(fd, uid, gid) }; - Errno::result(res)?; - - Ok(()) + nix::unistd::fchown(fd, owner, group).map_err(|err| err.into()) } /// Define permissions, owner and group when creating files/dirs