diff options
author | Aleksey Kladov <[email protected]> | 2020-02-17 14:33:31 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-17 14:35:06 +0000 |
commit | 94fb9ad6b3167e8b8073a09fcf0cb135f383d3d2 (patch) | |
tree | 89291f15bc0f6208e8f31e9a57b34a11e77ad1e4 /xtask/src/not_bash.rs | |
parent | 13d793929a8f7732a586cc2f8a2322f2c02fd582 (diff) |
Fix extension name
Diffstat (limited to 'xtask/src/not_bash.rs')
-rw-r--r-- | xtask/src/not_bash.rs | 30 |
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 @@ | |||
2 | use std::{ | 2 | use 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 | ||
71 | pub 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 | |||
77 | pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> { | 69 | pub 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 | ||
86 | pub 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)] |
106 | pub fn run_process(cmd: String, echo: bool) -> Result<String> { | 82 | pub 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)) |