single place for copy file

master
rascul 5 years ago
parent a172f4c645
commit 977bf2f147

@ -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<PathBuf>,
@ -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 {
copy_file(&f, &t)?;
set_perms(&t, Permissions::from_mode(mode))?;
}
} else if verbose {
println!("Skipping {}", &f.display());
}

@ -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(())
}

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

Loading…
Cancel
Save