Use walkdir crate
It's more efficient than the fs::read_dir API
This commit is contained in:
parent
5f1da8e533
commit
e17b02d9b9
@ -3805,6 +3805,7 @@ dependencies = [
|
||||
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -9,3 +9,4 @@ regex = "1"
|
||||
serde = { version = "1.0.8", features = ["derive"] }
|
||||
serde_json = "1.0.2"
|
||||
lazy_static = "1"
|
||||
walkdir = "2"
|
||||
|
@ -3,7 +3,7 @@
|
||||
//! This library contains the tidy lints and exposes it
|
||||
//! to be used by tools.
|
||||
|
||||
use std::fs;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
@ -72,18 +72,14 @@ fn walk_many(paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn F
|
||||
}
|
||||
|
||||
fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
|
||||
if let Ok(dir) = fs::read_dir(path) {
|
||||
for entry in dir {
|
||||
let entry = t!(entry);
|
||||
let kind = t!(entry.file_type());
|
||||
let path = entry.path();
|
||||
if kind.is_dir() {
|
||||
if !skip(&path) {
|
||||
walk(&path, skip, f);
|
||||
}
|
||||
} else {
|
||||
f(&path);
|
||||
let walker = WalkDir::new(path).into_iter()
|
||||
.filter_entry(|e| !skip(e.path()));
|
||||
for entry in walker {
|
||||
if let Ok(entry) = entry {
|
||||
if entry.file_type().is_dir() {
|
||||
continue;
|
||||
}
|
||||
f(&entry.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user