use std::fs;
use error::Error;
use operation::Operation;
use super::Result;
use super::exists as exists;
pub fn create(path: &str) -> Result<()> {
if exists(path) { return Ok(()); }
match fs::create_dir_all(path) {
Ok(_) => {
debug!("Successfully created '{}'", path);
Ok(())
},
Err(error) => {
if exists(path) {
Ok(())
} else {
Err(Error::with_cause(&Operation::Create, path, error)) }
}
}
}
pub fn delete(path: &str) -> Result<()> {
if !exists(path) { return Ok(()); }
match fs::remove_dir_all(path) {
Ok(_) => {
debug!("Successfully deleted '{}'", path);
Ok(())
},
Err(error) => {
if !exists(path) {
Ok(())
} else {
Err(Error::with_cause(&Operation::Delete, path, error))
}
}
}
}