Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times
This commit is contained in:
parent
9efa9fd1c4
commit
2387942588
|
@ -3,6 +3,7 @@ use clap::{App, ArgMatches, SubCommand};
|
||||||
use mdbook::errors::*;
|
use mdbook::errors::*;
|
||||||
use mdbook::MDBook;
|
use mdbook::MDBook;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
// Create clap subcommand arguments
|
// Create clap subcommand arguments
|
||||||
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
|
@ -29,7 +30,11 @@ pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> {
|
||||||
Some(dest_dir) => dest_dir.into(),
|
Some(dest_dir) => dest_dir.into(),
|
||||||
None => book.root.join(&book.config.build.build_dir),
|
None => book.root.join(&book.config.build.build_dir),
|
||||||
};
|
};
|
||||||
fs::remove_dir_all(&dir_to_remove).chain_err(|| "Unable to remove the build directory")?;
|
|
||||||
|
let path_to_dir_to_remove = Path::new(&dir_to_remove);
|
||||||
|
if path_to_dir_to_remove.exists() {
|
||||||
|
fs::remove_dir_all(&dir_to_remove).chain_err(|| "Unable to remove the build directory")?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue