diff options
Diffstat (limited to 'cli/fs_util.rs')
-rw-r--r-- | cli/fs_util.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/cli/fs_util.rs b/cli/fs_util.rs index a862e4bd3..462bbdddb 100644 --- a/cli/fs_util.rs +++ b/cli/fs_util.rs @@ -161,6 +161,16 @@ where Ok(target_files) } +// Asynchronously removes a directory and all its descendants, but does not error +// when the directory does not exist. +pub async fn remove_dir_all_if_exists(path: &Path) -> std::io::Result<()> { + let result = tokio::fs::remove_dir_all(path).await; + match result { + Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()), + _ => result, + } +} + #[cfg(test)] mod tests { use super::*; |