use std::fs; use std::path::Path; pub struct Repository { base_path: String, } impl Repository { pub fn new(base_path: &str) -> Repository { // create the base directory path create_directory(base_path); let sub_dirs: Vec<&str> = vec!["ingest", "archive", "output"]; for s in sub_dirs { create_directory(Path::new(base_path).join(s).to_str().unwrap()); } return Repository { base_path: String::from(base_path), }; } } fn create_directory(path: &str) { let d = Path::new(path); if d.is_dir() { println!("Directory {} already exists.", path); } else { match fs::create_dir(path) { Ok(_) => { println!("Creating directory {}.", path); }, Err(e) => { eprintln!("Error creating {}: {}", path, e); std::process::exit(1); } } } }