From ff9e0b0add933c27edf122a0711463b1991ba4f6 Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Mon, 11 Dec 2017 17:29:32 +1100 Subject: [PATCH] Made sure create_missing also creates the parent directory --- src/book/book.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/book/book.rs b/src/book/book.rs index e806f9fe..7a03eae7 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Display, Formatter}; use std::path::{Path, PathBuf}; use std::collections::VecDeque; -use std::fs::File; +use std::fs::{self, File}; use std::io::{Read, Write}; 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 { let filename = src_dir.join(&link.location); if !filename.exists() { + if let Some(parent) = filename.parent() { + if !parent.exists() { + fs::create_dir_all(parent)?; + } + } debug!("[*] Creating missing file {}", filename.display()); let mut f = File::create(&filename)?;