From 5abbf991d9df2535e3a698f5b93eac904f872317 Mon Sep 17 00:00:00 2001 From: rascul Date: Tue, 27 Aug 2019 15:01:19 -0500 Subject: [PATCH] util stuff into single file --- src/{util/perms.rs => util.rs} | 27 ++++++++++++++++++++++++++- src/util/copy_file.rs | 17 ----------------- src/util/mkdir.rs | 16 ---------------- src/util/mod.rs | 7 ------- 4 files changed, 26 insertions(+), 41 deletions(-) rename src/{util/perms.rs => util.rs} (50%) delete mode 100644 src/util/copy_file.rs delete mode 100644 src/util/mkdir.rs delete mode 100644 src/util/mod.rs diff --git a/src/util/perms.rs b/src/util.rs similarity index 50% rename from src/util/perms.rs rename to src/util.rs index 588366e..7f19c96 100644 --- a/src/util/perms.rs +++ b/src/util.rs @@ -1,4 +1,4 @@ -use std::fs::{metadata, set_permissions, Permissions}; +use std::fs::{copy, create_dir, metadata, set_permissions, Permissions}; use std::path::PathBuf; use crate::error::*; @@ -25,3 +25,28 @@ pub fn set_perms(path: &PathBuf, perms: Permissions) -> MkrootResult<()> { Ok(()) } + +pub fn mkdir(dir: &PathBuf) -> MkrootResult<()> { + if let Err(e) = create_dir(&dir) { + return Err(MkrootError::from(format!( + "Error creating directory {}: {}", + &dir.display(), + e + ))); + } + + Ok(()) +} + +pub fn copy_file(src: &PathBuf, dst: &PathBuf) -> MkrootResult<()> { + if let Err(e) = copy(&src, &dst) { + return Err(MkrootError::from(format!( + "Error copying file from {} to {}: {}", + &src.display(), + &dst.display(), + e + ))); + } + + Ok(()) +} diff --git a/src/util/copy_file.rs b/src/util/copy_file.rs deleted file mode 100644 index c55d04e..0000000 --- a/src/util/copy_file.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::fs::copy; -use std::path::PathBuf; - -use crate::error::*; - -pub fn copy_file(src: &PathBuf, dst: &PathBuf) -> MkrootResult<()> { - if let Err(e) = copy(&src, &dst) { - return Err(MkrootError::from(format!( - "Error copying file from {} to {}: {}", - &src.display(), - &dst.display(), - e - ))); - } - - Ok(()) -} diff --git a/src/util/mkdir.rs b/src/util/mkdir.rs deleted file mode 100644 index 203cac0..0000000 --- a/src/util/mkdir.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::fs::create_dir; -use std::path::PathBuf; - -use crate::error::*; - -pub fn mkdir(dir: &PathBuf) -> MkrootResult<()> { - if let Err(e) = create_dir(&dir) { - return Err(MkrootError::from(format!( - "Error creating directory {}: {}", - &dir.display(), - e - ))); - } - - Ok(()) -} diff --git a/src/util/mod.rs b/src/util/mod.rs deleted file mode 100644 index 71d8bd5..0000000 --- a/src/util/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod copy_file; -mod mkdir; -mod perms; - -pub use crate::util::copy_file::copy_file; -pub use crate::util::mkdir::mkdir; -pub use crate::util::perms::*;