diff --git a/src/main.rs b/src/main.rs index dc32560..27622cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ mod config; mod dirs; mod error; mod files; -mod perms; mod skel; +mod util; use std::path::PathBuf; diff --git a/src/skel.rs b/src/skel.rs index 97376af..38634d6 100644 --- a/src/skel.rs +++ b/src/skel.rs @@ -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::path::PathBuf; use crate::config::Config; use crate::error::*; +use crate::util::{get_perms, set_perms}; pub fn copy(config: &Config) -> MkrootResult<()> { if config.verbose { @@ -104,30 +105,6 @@ fn copy_file(src: &PathBuf, dst: &PathBuf) -> MkrootResult<()> { Ok(()) } - -fn get_perms(path: &PathBuf) -> MkrootResult { - 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<()> { if let Err(e) = create_dir(path) { return Err(MkrootError::from(format!( diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 0000000..9150df6 --- /dev/null +++ b/src/util/mod.rs @@ -0,0 +1,3 @@ +mod perms; + +pub use crate::util::perms::*; diff --git a/src/perms.rs b/src/util/perms.rs similarity index 90% rename from src/perms.rs rename to src/util/perms.rs index 3cd864f..588366e 100644 --- a/src/perms.rs +++ b/src/util/perms.rs @@ -1,4 +1,4 @@ -use std::fs::{set_permissions, metadata, Permissions}; +use std::fs::{metadata, set_permissions, Permissions}; use std::path::PathBuf; use crate::error::*;