zvault/src/util/fs.rs

22 lines
604 B
Rust
Raw Normal View History

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-03-22 18:58:56 +00:00
pub fn chown<P: AsRef<Path>>(path: P, uid: libc::uid_t, gid: libc::gid_t) -> Result<(), io::Error> {
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(()),
-1 => Err(io::Error::last_os_error()),
_ => unreachable!()
2017-03-22 18:58:56 +00:00
}
}
}
pub use self::linux::*;