From 5acb467894053cb0342eb6ded4d162b4a6912483 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 19:03:45 +0100 Subject: Move rm_rf to not-bash --- xtask/src/not_bash.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'xtask/src/not_bash.rs') diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index 1a7cb7114..3e30e7279 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs @@ -4,7 +4,7 @@ use std::{ env, ffi::OsStr, fs, - path::PathBuf, + path::{Path, PathBuf}, process::{Command, Stdio}, }; @@ -31,6 +31,16 @@ pub mod fs2 { fs::copy(from, to) .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display())) } + + pub fn remove_file>(path: P) -> Result<()> { + let path = path.as_ref(); + fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display())) + } + + pub fn remove_dir_all>(path: P) -> Result<()> { + let path = path.as_ref(); + fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display())) + } } macro_rules! _run { @@ -64,6 +74,15 @@ pub fn rm(glob: &str) -> Result<()> { Ok(()) } +pub fn rm_rf(path: impl AsRef) -> Result<()> { + let path = path.as_ref(); + if path.is_file() { + fs2::remove_file(path) + } else { + fs2::remove_dir_all(path) + } +} + pub fn ls(glob: &str) -> Result> { let cwd = Env::with(|env| env.cwd()); let mut res = Vec::new(); -- cgit v1.2.3