Made sure create_missing also creates the parent directory

This commit is contained in:
Michael Bryan 2017-12-11 17:29:32 +11:00
parent 148511eceb
commit ff9e0b0add
No known key found for this signature in database
GPG Key ID: E9C602B0D9A998DC
1 changed files with 6 additions and 1 deletions

View File

@ -1,7 +1,7 @@
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fs::File; use std::fs::{self, File};
use std::io::{Read, Write}; use std::io::{Read, Write};
use super::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem}; use super::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem};
@ -42,6 +42,11 @@ fn create_missing(src_dir: &Path, summary: &Summary) -> Result<()> {
if let SummaryItem::Link(ref link) = *next { if let SummaryItem::Link(ref link) = *next {
let filename = src_dir.join(&link.location); let filename = src_dir.join(&link.location);
if !filename.exists() { if !filename.exists() {
if let Some(parent) = filename.parent() {
if !parent.exists() {
fs::create_dir_all(parent)?;
}
}
debug!("[*] Creating missing file {}", filename.display()); debug!("[*] Creating missing file {}", filename.display());
let mut f = File::create(&filename)?; let mut f = File::create(&filename)?;