Skip to content

Commit

Permalink
Add EmptyPath for FchownatFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
tathanhdinh committed Sep 23, 2019
1 parent 2fc246c commit f944ee5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,20 @@ pub fn chown<P: ?Sized + NixPath>(path: &P, owner: Option<Uid>, group: Option<Gi
}

/// Flags for `fchownat` function.
#[cfg(not(target_os = "linux"))]
#[derive(Clone, Copy, Debug)]
pub enum FchownatFlags {
FollowSymlink,
NoFollowSymlink,
}

#[cfg(target_os = "linux")]
pub enum FchownatFlags {
FollowSymlink,
NoFollowSymlink,
EmptyPath,
}

/// Change the ownership of the file at `path` to be owned by the specified
/// `owner` (user) and `group`.
///
Expand Down Expand Up @@ -662,9 +670,17 @@ pub fn fchownat<P: ?Sized + NixPath>(
flag: FchownatFlags,
) -> Result<()> {
let atflag =
match flag {
FchownatFlags::FollowSymlink => AtFlags::empty(),
FchownatFlags::NoFollowSymlink => AtFlags::AT_SYMLINK_NOFOLLOW,
if cfg!(target_os = "linux") {
match flag {
FchownatFlags::FollowSymlink => AtFlags::empty(),
FchownatFlags::NoFollowSymlink => AtFlags::AT_SYMLINK_NOFOLLOW,
_ => AtFlags::AT_EMPTY_PATH,
}
} else {
match flag {
FchownatFlags::FollowSymlink => AtFlags::empty(),
_ => AtFlags::AT_SYMLINK_NOFOLLOW,
}
};
let res = path.with_nix_path(|cstr| unsafe {
let (uid, gid) = chown_raw_ids(owner, group);
Expand Down

0 comments on commit f944ee5

Please sign in to comment.