aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/not_bash.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/not_bash.rs')
-rw-r--r--xtask/src/not_bash.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs
index a2e47c7af..4ec1efa73 100644
--- a/xtask/src/not_bash.rs
+++ b/xtask/src/not_bash.rs
@@ -2,6 +2,8 @@
2use std::{ 2use std::{
3 cell::RefCell, 3 cell::RefCell,
4 env, 4 env,
5 ffi::OsStr,
6 fs,
5 path::PathBuf, 7 path::PathBuf,
6 process::{Command, Stdio}, 8 process::{Command, Stdio},
7}; 9};
@@ -33,6 +35,31 @@ impl Drop for Pushd {
33 } 35 }
34} 36}
35 37
38pub fn rm(glob: &str) -> Result<()> {
39 let cwd = Env::with(|env| env.cwd());
40 ls(glob)?.into_iter().try_for_each(|it| fs::remove_file(cwd.join(it)))?;
41 Ok(())
42}
43
44pub fn ls(glob: &str) -> Result<Vec<PathBuf>> {
45 let cwd = Env::with(|env| env.cwd());
46 let mut res = Vec::new();
47 for entry in fs::read_dir(&cwd)? {
48 let entry = entry?;
49 if matches(&entry.file_name(), glob) {
50 let path = entry.path();
51 let path = path.strip_prefix(&cwd).unwrap();
52 res.push(path.to_path_buf())
53 }
54 }
55 return Ok(res);
56
57 fn matches(file_name: &OsStr, glob: &str) -> bool {
58 assert!(glob.starts_with('*'));
59 file_name.to_string_lossy().ends_with(&glob[1..])
60 }
61}
62
36#[doc(hidden)] 63#[doc(hidden)]
37pub fn run_process(cmd: String, echo: bool) -> Result<String> { 64pub fn run_process(cmd: String, echo: bool) -> Result<String> {
38 run_process_inner(&cmd, echo).with_context(|| format!("process `{}` failed", cmd)) 65 run_process_inner(&cmd, echo).with_context(|| format!("process `{}` failed", cmd))