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

Implement --owner and --perms #689

Merged
merged 11 commits into from
Jul 13, 2023
26 changes: 26 additions & 0 deletions src/system/file/chown.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::{fs::File, io, os::fd::AsRawFd};

use crate::{
cutils::cerr,
system::interface::{GroupId, UserId},
};

mod sealed {
use std::fs::File;

pub(crate) trait Sealed {}
pvdrz marked this conversation as resolved.
Show resolved Hide resolved

impl Sealed for File {}
}

pub(crate) trait Chown: sealed::Sealed {
fn chown(&self, uid: UserId, gid: GroupId) -> io::Result<()>;
}

impl Chown for File {
fn chown(&self, owner: UserId, group: GroupId) -> io::Result<()> {
let fd = self.as_raw_fd();

cerr(unsafe { libc::fchown(fd, owner, group) }).map(|_| ())
}
}
1 change: 1 addition & 0 deletions src/system/file.rs → src/system/file/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ mod tests {
assert!(f.unlock().is_ok());
}
}

5 changes: 5 additions & 0 deletions src/system/file/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod chown;
mod lock;

pub(crate) use lock::Lockable;
pub(crate) use chown::Chown;