mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-03 12:01:08 +00:00
use nix::unistd::fchown
instead of re-implementing it, now that we depend on >=0.19 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
1db9a5bc0e
commit
6bb932e604
@ -7,7 +7,6 @@ use anyhow::{bail, Error};
|
|||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
use nix::unistd::{Gid, Uid};
|
use nix::unistd::{Gid, Uid};
|
||||||
use nix::sys::stat;
|
use nix::sys::stat;
|
||||||
use nix::errno::Errno;
|
|
||||||
|
|
||||||
pub mod acl;
|
pub mod acl;
|
||||||
|
|
||||||
@ -27,16 +26,7 @@ pub mod xattr;
|
|||||||
|
|
||||||
/// Change ownership of an open file handle
|
/// Change ownership of an open file handle
|
||||||
pub fn fchown(fd: RawFd, owner: Option<Uid>, group: Option<Gid>) -> Result<(), Error> {
|
pub fn fchown(fd: RawFd, owner: Option<Uid>, group: Option<Gid>) -> Result<(), Error> {
|
||||||
// According to the POSIX specification, -1 is used to indicate that owner and group
|
nix::unistd::fchown(fd, owner, group).map_err(|err| err.into())
|
||||||
// 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(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define permissions, owner and group when creating files/dirs
|
/// Define permissions, owner and group when creating files/dirs
|
||||||
|
Loading…
Reference in New Issue
Block a user