aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/not_bash.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-17 14:33:31 +0000
committerAleksey Kladov <[email protected]>2020-02-17 14:35:06 +0000
commit94fb9ad6b3167e8b8073a09fcf0cb135f383d3d2 (patch)
tree89291f15bc0f6208e8f31e9a57b34a11e77ad1e4 /xtask/src/not_bash.rs
parent13d793929a8f7732a586cc2f8a2322f2c02fd582 (diff)
Fix extension name
Diffstat (limited to 'xtask/src/not_bash.rs')
-rw-r--r--xtask/src/not_bash.rs30
1 files changed, 3 insertions, 27 deletions
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs
index 3e30e7279..d5577cce9 100644
--- a/xtask/src/not_bash.rs
+++ b/xtask/src/not_bash.rs
@@ -2,8 +2,6 @@
2use std::{ 2use std::{
3 cell::RefCell, 3 cell::RefCell,
4 env, 4 env,
5 ffi::OsStr,
6 fs,
7 path::{Path, PathBuf}, 5 path::{Path, PathBuf},
8 process::{Command, Stdio}, 6 process::{Command, Stdio},
9}; 7};
@@ -68,14 +66,11 @@ impl Drop for Pushd {
68 } 66 }
69} 67}
70 68
71pub fn rm(glob: &str) -> Result<()> {
72 let cwd = Env::with(|env| env.cwd());
73 ls(glob)?.into_iter().try_for_each(|it| fs::remove_file(cwd.join(it)))?;
74 Ok(())
75}
76
77pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> { 69pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> {
78 let path = path.as_ref(); 70 let path = path.as_ref();
71 if !path.exists() {
72 return Ok(());
73 }
79 if path.is_file() { 74 if path.is_file() {
80 fs2::remove_file(path) 75 fs2::remove_file(path)
81 } else { 76 } else {
@@ -83,25 +78,6 @@ pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> {
83 } 78 }
84} 79}
85 80
86pub fn ls(glob: &str) -> Result<Vec<PathBuf>> {
87 let cwd = Env::with(|env| env.cwd());
88 let mut res = Vec::new();
89 for entry in fs::read_dir(&cwd)? {
90 let entry = entry?;
91 if matches(&entry.file_name(), glob) {
92 let path = entry.path();
93 let path = path.strip_prefix(&cwd).unwrap();
94 res.push(path.to_path_buf())
95 }
96 }
97 return Ok(res);
98
99 fn matches(file_name: &OsStr, glob: &str) -> bool {
100 assert!(glob.starts_with('*'));
101 file_name.to_string_lossy().ends_with(&glob[1..])
102 }
103}
104
105#[doc(hidden)] 81#[doc(hidden)]
106pub fn run_process(cmd: String, echo: bool) -> Result<String> { 82pub fn run_process(cmd: String, echo: bool) -> Result<String> {
107 run_process_inner(&cmd, echo).with_context(|| format!("process `{}` failed", cmd)) 83 run_process_inner(&cmd, echo).with_context(|| format!("process `{}` failed", cmd))