Only create directory if it does not exist
This commit is contained in:
parent
84f426297e
commit
2bf09e7737
1 changed files with 6 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue