fix(init): avoid TOCTTOU bug on syntax CSS dir

Fixes https://github.com/rust-lang/mdBook/pull/1652#discussion_r717622169
This commit is contained in:
Michael Howell 2021-09-28 08:35:58 -07:00
parent 048042ff59
commit 1de4ab8939
1 changed files with 1 additions and 3 deletions

View File

@ -152,9 +152,7 @@ impl BookBuilder {
js.write_all(theme::JS)?; js.write_all(theme::JS)?;
let syntax_dir = cssdir.join("syntax"); let syntax_dir = cssdir.join("syntax");
if !syntax_dir.exists() { fs::create_dir_all(syntax_dir)?;
fs::create_dir(&syntax_dir)?;
}
let mut highlight_css = File::create(syntax_dir.join("light.css"))?; let mut highlight_css = File::create(syntax_dir.join("light.css"))?;
highlight_css.write_all(theme::SYNTAX_LIGHT_CSS)?; highlight_css.write_all(theme::SYNTAX_LIGHT_CSS)?;