From 1de4ab89395a052726050832b193f7a3c8e56e37 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 28 Sep 2021 08:35:58 -0700 Subject: [PATCH] fix(init): avoid TOCTTOU bug on syntax CSS dir Fixes https://github.com/rust-lang/mdBook/pull/1652#discussion_r717622169 --- src/book/init.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/book/init.rs b/src/book/init.rs index e7e26409..0dacab98 100644 --- a/src/book/init.rs +++ b/src/book/init.rs @@ -152,9 +152,7 @@ impl BookBuilder { js.write_all(theme::JS)?; let syntax_dir = cssdir.join("syntax"); - if !syntax_dir.exists() { - fs::create_dir(&syntax_dir)?; - } + fs::create_dir_all(syntax_dir)?; let mut highlight_css = File::create(syntax_dir.join("light.css"))?; highlight_css.write_all(theme::SYNTAX_LIGHT_CSS)?;