diff options
Diffstat (limited to 'xtask/src/not_bash.rs')
-rw-r--r-- | xtask/src/not_bash.rs | 21 |
1 files changed, 20 insertions, 1 deletions
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::{ | |||
4 | env, | 4 | env, |
5 | ffi::OsStr, | 5 | ffi::OsStr, |
6 | fs, | 6 | fs, |
7 | path::PathBuf, | 7 | path::{Path, PathBuf}, |
8 | process::{Command, Stdio}, | 8 | process::{Command, Stdio}, |
9 | }; | 9 | }; |
10 | 10 | ||
@@ -31,6 +31,16 @@ pub mod fs2 { | |||
31 | fs::copy(from, to) | 31 | fs::copy(from, to) |
32 | .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display())) | 32 | .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display())) |
33 | } | 33 | } |
34 | |||
35 | pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> { | ||
36 | let path = path.as_ref(); | ||
37 | fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display())) | ||
38 | } | ||
39 | |||
40 | pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()> { | ||
41 | let path = path.as_ref(); | ||
42 | fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display())) | ||
43 | } | ||
34 | } | 44 | } |
35 | 45 | ||
36 | macro_rules! _run { | 46 | macro_rules! _run { |
@@ -64,6 +74,15 @@ pub fn rm(glob: &str) -> Result<()> { | |||
64 | Ok(()) | 74 | Ok(()) |
65 | } | 75 | } |
66 | 76 | ||
77 | pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> { | ||
78 | let path = path.as_ref(); | ||
79 | if path.is_file() { | ||
80 | fs2::remove_file(path) | ||
81 | } else { | ||
82 | fs2::remove_dir_all(path) | ||
83 | } | ||
84 | } | ||
85 | |||
67 | pub fn ls(glob: &str) -> Result<Vec<PathBuf>> { | 86 | pub fn ls(glob: &str) -> Result<Vec<PathBuf>> { |
68 | let cwd = Env::with(|env| env.cwd()); | 87 | let cwd = Env::with(|env| env.cwd()); |
69 | let mut res = Vec::new(); | 88 | let mut res = Vec::new(); |