Fix updater permissions and refactor existing code.
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user