Skip to content

Commit 255e8f2

Browse files
committed
no directories
1 parent dfb4dfd commit 255e8f2

File tree

1 file changed

+4
-56
lines changed

1 file changed

+4
-56
lines changed

tools/unsafe-finder/src/main.rs

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::env;
22
use std::fs;
33
use std::error::Error;
4-
use std::io;
54
use std::process;
65
use std::path::Path;
76

@@ -218,51 +217,6 @@ fn handle_file(path:&Path) -> Result<(), Box<dyn Error>> {
218217
Ok(())
219218
}
220219

221-
fn handle_dir(path:&Path) -> io::Result<()> {
222-
// https://users.rust-lang.org/t/testable-way-to-iterate-over-a-directory/81440
223-
let mut dirs = Vec::new();
224-
let mut dir_index = 0;
225-
let mut dir_reader = fs::read_dir(path)?;
226-
let mut had_files = false;
227-
loop {
228-
match dir_reader.next() {
229-
Some(entry) => {
230-
let cur_path = entry?.path();
231-
had_files = true;
232-
if cur_path.is_dir() {
233-
dirs.push(cur_path);
234-
continue;
235-
}
236-
237-
if cur_path.is_file() {
238-
if let Err(err) = handle_file(&cur_path) {
239-
println!("error processing {}: {}", cur_path.display(), err);
240-
process::exit(1);
241-
}
242-
continue;
243-
}
244-
}
245-
_ => {
246-
if !had_files && !dirs.is_empty() {
247-
let target = dirs[(dir_index - 1).max(0)].to_owned();
248-
if let Err(err) = handle_file(&target) {
249-
println!("error processing {}: {}", target.display(), err);
250-
process::exit(1);
251-
}
252-
}
253-
if dir_index == dirs.len() {
254-
break;
255-
}
256-
dir_reader = dirs[dir_index].read_dir()?;
257-
had_files = false;
258-
dir_index += 1;
259-
}
260-
}
261-
}
262-
263-
Ok(())
264-
}
265-
266220
fn main() {
267221
let mut args = env::args();
268222
let _ = args.next(); // executable name
@@ -274,16 +228,10 @@ fn main() {
274228
}
275229

276230
for arg in args {
277-
let path = Path::new(&arg);
278-
if path.is_file() {
279-
if let Err(err) = handle_file(&path) {
280-
eprintln!("error processing {}: {}", arg, err);
281-
process::exit(1);
282-
}
283-
} else if path.is_dir() {
284-
handle_dir(&path).unwrap();
285-
} else {
286-
eprintln!("could not open {}", arg);
231+
let path = Path::new(&arg);
232+
if let Err(err) = handle_file(&path) {
233+
eprintln!("error processing {}: {}", arg, err);
234+
process::exit(1);
287235
}
288236
}
289237
}

0 commit comments

Comments
 (0)