Fix: implicitely create directories on file saving

This commit is contained in:
Matthias Beyer 2016-03-10 19:05:38 +01:00
parent 7dde6c2a56
commit a9a64d4ab6
1 changed files with 7 additions and 1 deletions

View File

@ -2,7 +2,7 @@
use error::{StoreError, StoreErrorKind};
use std::io::{Seek, SeekFrom};
use std::path::{Path, PathBuf};
use std::fs::{File, OpenOptions};
use std::fs::{File, OpenOptions, create_dir_all};
/**
* LazyFile type
@ -20,6 +20,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);
}
}
OpenOptions::new().write(true).read(true).create(true).open(p)
}