//! This library contains the tidy lints and exposes it
//! to be used by tools.
-use std::fs;
+use walkdir::{DirEntry, WalkDir};
+use std::fs::File;
+use std::io::Read;
use std::path::Path;
"src/tools/lld",
"src/tools/lldb",
"src/target",
- "src/stdsimd",
+ "src/stdarch",
"src/rust-sgx",
"target",
"vendor",
skip.iter().any(|p| path.ends_with(p))
}
-fn walk_many(paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
+
+fn walk_many(
+ paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)
+) {
for path in paths {
walk(path, skip, 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);
+fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)) {
+ let mut contents = String::new();
+ walk_no_read(path, skip, &mut |entry| {
+ contents.clear();
+ if t!(File::open(entry.path()), entry.path()).read_to_string(&mut contents).is_err() {
+ contents.clear();
+ }
+ f(&entry, &contents);
+ });
+}
+
+fn walk_no_read(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry)) {
+ 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);
}
}
}