Skip to content

Commit 2387942

Browse files
committed
Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times
1 parent 9efa9fd commit 2387942

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cmd/clean.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clap::{App, ArgMatches, SubCommand};
33
use mdbook::errors::*;
44
use mdbook::MDBook;
55
use std::fs;
6+
use std::path::Path;
67

78
// Create clap subcommand arguments
89
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
@@ -29,7 +30,11 @@ pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> {
2930
Some(dest_dir) => dest_dir.into(),
3031
None => book.root.join(&book.config.build.build_dir),
3132
};
32-
fs::remove_dir_all(&dir_to_remove).chain_err(|| "Unable to remove the build directory")?;
33+
34+
let path_to_dir_to_remove = Path::new(&dir_to_remove);
35+
if path_to_dir_to_remove.exists() {
36+
fs::remove_dir_all(&dir_to_remove).chain_err(|| "Unable to remove the build directory")?;
37+
}
3338

3439
Ok(())
3540
}

0 commit comments

Comments
 (0)