From 977bf2f147b95472eab04e24727d31b58b2a452f Mon Sep 17 00:00:00 2001 From: rascul Date: Mon, 26 Aug 2019 20:00:20 -0500 Subject: [PATCH] single place for copy file --- src/files/mkroot_files.rs | 16 ++++------------ src/util/copy_file.rs | 17 +++++++++++++++++ src/util/mod.rs | 2 ++ 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 src/util/copy_file.rs diff --git a/src/files/mkroot_files.rs b/src/files/mkroot_files.rs index 4f049d3..275882b 100644 --- a/src/files/mkroot_files.rs +++ b/src/files/mkroot_files.rs @@ -1,4 +1,4 @@ -use std::fs::{copy as fscopy, File, Permissions}; +use std::fs::{File, Permissions}; use std::os::unix::fs::PermissionsExt; use std::path::PathBuf; use std::process::Command; @@ -7,7 +7,7 @@ use regex::Regex; use crate::config::Config; use crate::error::*; -use crate::util::set_perms; +use crate::util::{copy_file, set_perms}; pub struct Files { pub bins: Vec, @@ -216,16 +216,8 @@ impl Files { println!("Copying {} to {}", &f.display(), &t.display()); } - if let Err(e) = fscopy(&f, &t) { - return Err(MkrootError::from(format!( - "Error copying file from {} to {}: {}", - &f.display(), - &t.display(), - e - ))); - } else { - set_perms(&t, Permissions::from_mode(mode))?; - } + copy_file(&f, &t)?; + set_perms(&t, Permissions::from_mode(mode))?; } else if verbose { println!("Skipping {}", &f.display()); } diff --git a/src/util/copy_file.rs b/src/util/copy_file.rs new file mode 100644 index 0000000..c55d04e --- /dev/null +++ b/src/util/copy_file.rs @@ -0,0 +1,17 @@ +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/mod.rs b/src/util/mod.rs index 9150df6..77e75e8 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,3 +1,5 @@ +mod copy_file; mod perms; +pub use crate::util::copy_file::copy_file; pub use crate::util::perms::*;