Fix updater permissions and refactor existing code.

This commit is contained in:
Gav Wood
2016-12-16 18:17:15 +01:00
parent b89d10239b
commit 14e4fefbcf
4 changed files with 13 additions and 14 deletions

View File

@@ -86,18 +86,15 @@ pub mod ethereum {
}
/// Restricts the permissions of given path only to the owner.
#[cfg(not(windows))]
pub fn restrict_permissions_owner(file_path: &Path) -> Result<(), i32> {
let cstr = ::std::ffi::CString::new(file_path.to_str().unwrap()).unwrap();
match unsafe { ::libc::chmod(cstr.as_ptr(), ::libc::S_IWUSR | ::libc::S_IRUSR) } {
0 => Ok(()),
x => Err(x),
}
#[cfg(unix)]
pub fn restrict_permissions_owner(file_path: &Path, write: bool, executable: bool) -> Result<(), String> {
let perms = ::std::os::unix::fs::PermissionsExt::from_mode(0o400 + write as u32 * 0o200 + executable as u32 * 0o100);
::std::fs::set_permissions(file_path, perms).map_err(|e| format!("{:?}", e))
}
/// Restricts the permissions of given path only to the owner.
#[cfg(windows)]
pub fn restrict_permissions_owner(_file_path: &Path) -> Result<(), i32> {
#[cfg(not(unix))]
pub fn restrict_permissions_owner(_file_path: &Path) -> Result<(), String> {
//TODO: implement me
Ok(())
}