2017-03-22 18:58:56 +00:00
|
|
|
mod linux {
|
|
|
|
use libc;
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
use std::io;
|
|
|
|
use std::ffi::CString;
|
|
|
|
use std::os::unix::ffi::OsStringExt;
|
|
|
|
|
2017-04-10 18:35:28 +00:00
|
|
|
#[inline]
|
2017-07-21 09:21:59 +00:00
|
|
|
pub fn chown<P: AsRef<Path>>(
|
|
|
|
path: P,
|
|
|
|
uid: libc::uid_t,
|
|
|
|
gid: libc::gid_t,
|
|
|
|
) -> Result<(), io::Error> {
|
2017-03-22 18:58:56 +00:00
|
|
|
let path = CString::new(path.as_ref().to_path_buf().into_os_string().into_vec()).unwrap();
|
2017-03-24 07:56:57 +00:00
|
|
|
let result = unsafe { libc::lchown((&path).as_ptr(), uid, gid) };
|
2017-03-22 18:58:56 +00:00
|
|
|
match result {
|
|
|
|
0 => Ok(()),
|
2017-04-12 12:53:11 +00:00
|
|
|
-1 => Err(io::Error::last_os_error()),
|
2017-07-21 09:21:59 +00:00
|
|
|
_ => unreachable!(),
|
2017-03-22 18:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use self::linux::*;
|
2017-07-04 10:36:39 +00:00
|
|
|
|
|
|
|
// Not testing since this requires root
|