From 238794258893336379bc56de645a63f7ddd6cc45 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sat, 5 Oct 2019 15:01:01 -0400 Subject: [PATCH 1/3] Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times --- src/cmd/clean.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmd/clean.rs b/src/cmd/clean.rs index 07c2fbc6..9bc95c28 100644 --- a/src/cmd/clean.rs +++ b/src/cmd/clean.rs @@ -3,6 +3,7 @@ use clap::{App, ArgMatches, SubCommand}; use mdbook::errors::*; use mdbook::MDBook; use std::fs; +use std::path::Path; // Create clap subcommand arguments 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(), 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(()) } From 3c25dba9b4cae73c01c4865f1efee54f5124df48 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sat, 5 Oct 2019 15:57:10 -0400 Subject: [PATCH 2/3] Revert "Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times" This reverts commit 238794258893336379bc56de645a63f7ddd6cc45. --- src/cmd/clean.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/cmd/clean.rs b/src/cmd/clean.rs index 9bc95c28..07c2fbc6 100644 --- a/src/cmd/clean.rs +++ b/src/cmd/clean.rs @@ -3,7 +3,6 @@ use clap::{App, ArgMatches, SubCommand}; use mdbook::errors::*; use mdbook::MDBook; use std::fs; -use std::path::Path; // Create clap subcommand arguments pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { @@ -30,11 +29,7 @@ pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> { Some(dest_dir) => dest_dir.into(), None => book.root.join(&book.config.build.build_dir), }; - - 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")?; - } + fs::remove_dir_all(&dir_to_remove).chain_err(|| "Unable to remove the build directory")?; Ok(()) } From 74313bb701e311dac5ce0d15e3c706d44d3b0bd8 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sat, 5 Oct 2019 15:59:34 -0400 Subject: [PATCH 3/3] Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times (uses existing path variable) --- src/cmd/clean.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/clean.rs b/src/cmd/clean.rs index 07c2fbc6..bf654b1c 100644 --- a/src/cmd/clean.rs +++ b/src/cmd/clean.rs @@ -29,7 +29,10 @@ pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> { Some(dest_dir) => dest_dir.into(), None => book.root.join(&book.config.build.build_dir), }; - fs::remove_dir_all(&dir_to_remove).chain_err(|| "Unable to remove the build directory")?; + + if dir_to_remove.exists() { + fs::remove_dir_all(&dir_to_remove).chain_err(|| "Unable to remove the build directory")?; + } Ok(()) }