Only create directory if it does not exist

This commit is contained in:
Matthias Beyer 2018-04-30 15:47:21 +02:00
parent 84f426297e
commit 2bf09e7737

View file

@ -187,9 +187,12 @@ fn open_file<A: AsRef<Path>>(p: A) -> ::std::io::Result<File> {
fn create_file<A: AsRef<Path>>(p: A) -> ::std::io::Result<File> {
if let Some(parent) = p.as_ref().parent() {
debug!("Implicitely creating directory: {:?}", parent);
if let Err(e) = create_dir_all(parent) {
return Err(e);
trace!("'{}' is directory = {}", parent.display(), parent.is_dir());
if !parent.is_dir() {
trace!("Implicitely creating directory: {:?}", parent);
if let Err(e) = create_dir_all(parent) {
return Err(e);
}
}
}
OpenOptions::new().write(true).read(true).create(true).open(p)