perms module for permissions

master
rascul 5 years ago
parent 8c391584d3
commit b7e6b5132a

@ -5,6 +5,7 @@ mod config;
mod dirs; mod dirs;
mod error; mod error;
mod files; mod files;
mod perms;
mod skel; mod skel;
use std::path::PathBuf; use std::path::PathBuf;

@ -0,0 +1,27 @@
use std::fs::{set_permissions, metadata, Permissions};
use std::path::PathBuf;
use crate::error::*;
pub fn get_perms(path: &PathBuf) -> MkrootResult<Permissions> {
match metadata(path) {
Ok(meta) => Ok(meta.permissions()),
Err(e) => Err(MkrootError::from(format!(
"Error retrieving metadata {}: {}",
path.display(),
e
))),
}
}
pub fn set_perms(path: &PathBuf, perms: Permissions) -> MkrootResult<()> {
if let Err(e) = set_permissions(path, perms) {
return Err(MkrootError::from(format!(
"Error setting permissions {}: {}",
path.display(),
e
)));
}
Ok(())
}
Loading…
Cancel
Save