Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EmptyPath for FchownatFlags #1128

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ pub fn chown<P: ?Sized + NixPath>(path: &P, owner: Option<Uid>, group: Option<Gi
pub enum FchownatFlags {
FollowSymlink,
NoFollowSymlink,
#[cfg(target_os = "linux")]
EmptyPath,
Comment on lines 631 to +635
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add this flag, then this type should no longer be an enum but a bitflag cause you can do AT_EMPTY_PATH and AT_SYMLINK_NOFOLLOW at the same time

}

/// Change the ownership of the file at `path` to be owned by the specified
Expand Down Expand Up @@ -661,11 +663,13 @@ pub fn fchownat<P: ?Sized + NixPath>(
group: Option<Gid>,
flag: FchownatFlags,
) -> Result<()> {
let atflag =
match flag {
FchownatFlags::FollowSymlink => AtFlags::empty(),
FchownatFlags::NoFollowSymlink => AtFlags::AT_SYMLINK_NOFOLLOW,
};
let atflag = match flag {
FchownatFlags::FollowSymlink => AtFlags::empty(),
FchownatFlags::NoFollowSymlink => AtFlags::AT_SYMLINK_NOFOLLOW,
#[cfg(target_os = "linux")]
FchownatFlags::EmptyPath => AtFlags::AT_EMPTY_PATH,
};

let res = path.with_nix_path(|cstr| unsafe {
let (uid, gid) = chown_raw_ids(owner, group);
libc::fchownat(at_rawfd(dirfd), cstr.as_ptr(), uid, gid,
Expand Down