1
Fork 0

Use walkdir crate

It's more efficient than the fs::read_dir API
This commit is contained in:
Mark Rousskov 2019-06-21 12:05:00 -04:00
parent 5f1da8e533
commit e17b02d9b9
3 changed files with 10 additions and 12 deletions

View file

@ -3805,6 +3805,7 @@ dependencies = [
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "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 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)", "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]] [[package]]

View file

@ -9,3 +9,4 @@ regex = "1"
serde = { version = "1.0.8", features = ["derive"] } serde = { version = "1.0.8", features = ["derive"] }
serde_json = "1.0.2" serde_json = "1.0.2"
lazy_static = "1" lazy_static = "1"
walkdir = "2"

View file

@ -3,7 +3,7 @@
//! This library contains the tidy lints and exposes it //! This library contains the tidy lints and exposes it
//! to be used by tools. //! to be used by tools.
use std::fs; use walkdir::WalkDir;
use std::path::Path; 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)) { fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
if let Ok(dir) = fs::read_dir(path) { let walker = WalkDir::new(path).into_iter()
for entry in dir { .filter_entry(|e| !skip(e.path()));
let entry = t!(entry); for entry in walker {
let kind = t!(entry.file_type()); if let Ok(entry) = entry {
let path = entry.path(); if entry.file_type().is_dir() {
if kind.is_dir() { continue;
if !skip(&path) {
walk(&path, skip, f);
}
} else {
f(&path);
} }
f(&entry.path());
} }
} }
} }