put perms in util module

master
rascul 5 years ago
parent b7e6b5132a
commit 8d8f842fb6

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

@ -1,9 +1,10 @@
use std::fs::{copy as fscopy, create_dir, metadata, read_dir, set_permissions, Permissions}; use std::fs::{copy as fscopy, create_dir, read_dir};
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf; use std::path::PathBuf;
use crate::config::Config; use crate::config::Config;
use crate::error::*; use crate::error::*;
use crate::util::{get_perms, set_perms};
pub fn copy(config: &Config) -> MkrootResult<()> { pub fn copy(config: &Config) -> MkrootResult<()> {
if config.verbose { if config.verbose {
@ -104,30 +105,6 @@ fn copy_file(src: &PathBuf, dst: &PathBuf) -> MkrootResult<()> {
Ok(()) Ok(())
} }
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
))),
}
}
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(())
}
fn mkdir(path: &PathBuf) -> MkrootResult<()> { fn mkdir(path: &PathBuf) -> MkrootResult<()> {
if let Err(e) = create_dir(path) { if let Err(e) = create_dir(path) {
return Err(MkrootError::from(format!( return Err(MkrootError::from(format!(

@ -0,0 +1,3 @@
mod perms;
pub use crate::util::perms::*;

@ -1,4 +1,4 @@
use std::fs::{set_permissions, metadata, Permissions}; use std::fs::{metadata, set_permissions, Permissions};
use std::path::PathBuf; use std::path::PathBuf;
use crate::error::*; use crate::error::*;
Loading…
Cancel
Save