Fix: implicitely create directories on file saving
This commit is contained in:
parent
7dde6c2a56
commit
a9a64d4ab6
1 changed files with 7 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
||||||
use error::{StoreError, StoreErrorKind};
|
use error::{StoreError, StoreErrorKind};
|
||||||
use std::io::{Seek, SeekFrom};
|
use std::io::{Seek, SeekFrom};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions, create_dir_all};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LazyFile type
|
* 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> {
|
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)
|
OpenOptions::new().write(true).read(true).create(true).open(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue