adept/src/repository.rs

40 lines
785 B
Rust
Raw Normal View History

2022-08-31 16:14:41 -04:00
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);
}
}
}
}