use mkdir from util module

master
rascul 5 years ago
parent 05d4580faa
commit fc9b5bc77e

@ -1,8 +1,9 @@
use std::fs::{create_dir, read_dir};
use std::fs::read_dir;
use std::path::PathBuf;
use crate::config::Config;
use crate::error::*;
use crate::util::mkdir;
static DIRS: &[&str] = &[
"bin", "dev", "etc", "home", "lib", "lib64", "proc", "root", "run", "sbin", "sys", "tmp",
@ -43,29 +44,21 @@ fn open(dir: &PathBuf, verbose: bool) -> MkrootResult<()> {
}
pub fn create(config: &Config) -> MkrootResult<()> {
mkdir(&config.root_dir, config.verbose)?;
if config.verbose {
println!("Creating directory {}", &config.root_dir.display());
}
mkdir(&config.root_dir)?;
for dir in DIRS {
let mut d = PathBuf::from(&config.root_dir);
d.push(&dir);
mkdir(&d, config.verbose)?;
}
Ok(())
}
fn mkdir(dir: &PathBuf, verbose: bool) -> MkrootResult<()> {
if !dir.exists() {
if verbose {
println!("Creating directory {}", &dir.display());
}
if let Err(e) = create_dir(&dir) {
return Err(MkrootError::from(format!(
"Error creating directory {}: {}",
&dir.display(),
e
)));
if config.verbose {
println!("Creating directory {}", dir);
}
mkdir(&d)?;
}
Ok(())

@ -1,10 +1,10 @@
use std::fs::{copy as fscopy, create_dir, read_dir};
use std::fs::{copy as fscopy, 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};
use crate::util::{get_perms, mkdir, set_perms};
pub fn copy(config: &Config) -> MkrootResult<()> {
if config.verbose {
@ -104,15 +104,3 @@ fn copy_file(src: &PathBuf, dst: &PathBuf) -> MkrootResult<()> {
Ok(())
}
fn mkdir(path: &PathBuf) -> MkrootResult<()> {
if let Err(e) = create_dir(path) {
return Err(MkrootError::from(format!(
"Error creating directory {}: {}",
path.display(),
e
)));
}
Ok(())
}

@ -0,0 +1,16 @@
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(())
}

@ -1,5 +1,7 @@
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::*;

Loading…
Cancel
Save