Use a single WalkBuilder for multiple paths
This commit is contained in:
parent
d26a15563d
commit
19b272a94b
3 changed files with 45 additions and 44 deletions
|
@ -103,7 +103,7 @@ mod os_impl {
|
||||||
|
|
||||||
// FIXME: we don't need to look at all binaries, only files that have been modified in this branch
|
// FIXME: we don't need to look at all binaries, only files that have been modified in this branch
|
||||||
// (e.g. using `git ls-files`).
|
// (e.g. using `git ls-files`).
|
||||||
walk_no_read(path, |path| filter_dirs(path) || path.ends_with("src/etc"), &mut |entry| {
|
walk_no_read(&[path], |path| filter_dirs(path) || path.ends_with("src/etc"), &mut |entry| {
|
||||||
let file = entry.path();
|
let file = entry.path();
|
||||||
let extension = file.extension();
|
let extension = file.extension();
|
||||||
let scripts = ["py", "sh", "ps1"];
|
let scripts = ["py", "sh", "ps1"];
|
||||||
|
|
|
@ -49,8 +49,9 @@ fn check_entries(tests_path: &Path, bad: &mut bool) {
|
||||||
|
|
||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
check_entries(&path, bad);
|
check_entries(&path, bad);
|
||||||
for path in &[&path.join("ui"), &path.join("ui-fulldeps")] {
|
let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps"));
|
||||||
crate::walk::walk_no_read(path, |_| false, &mut |entry| {
|
let paths = [ui.as_path(), ui_fulldeps.as_path()];
|
||||||
|
crate::walk::walk_no_read(&paths, |_| false, &mut |entry| {
|
||||||
let file_path = entry.path();
|
let file_path = entry.path();
|
||||||
if let Some(ext) = file_path.extension() {
|
if let Some(ext) = file_path.extension() {
|
||||||
if ext == "stderr" || ext == "stdout" {
|
if ext == "stderr" || ext == "stdout" {
|
||||||
|
@ -82,4 +83,3 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -35,26 +35,24 @@ pub fn filter_dirs(path: &Path) -> bool {
|
||||||
|
|
||||||
/// Filter for only files that end in `.rs`.
|
/// Filter for only files that end in `.rs`.
|
||||||
pub fn filter_not_rust(path: &Path) -> bool {
|
pub fn filter_not_rust(path: &Path) -> bool {
|
||||||
!path.is_dir() && path.extension() != Some(OsStr::new("rs"))
|
path.extension() != Some(OsStr::new("rs")) && !path.is_dir()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn walk(
|
||||||
|
path: &Path,
|
||||||
|
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
||||||
|
f: &mut dyn FnMut(&DirEntry, &str),
|
||||||
|
) {
|
||||||
|
walk_many(&[path], skip, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_many(
|
pub fn walk_many(
|
||||||
paths: &[&Path],
|
paths: &[&Path],
|
||||||
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
||||||
f: &mut dyn FnMut(&DirEntry, &str),
|
f: &mut dyn FnMut(&DirEntry, &str),
|
||||||
) {
|
|
||||||
for path in paths {
|
|
||||||
walk(path, skip.clone(), f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn walk(
|
|
||||||
path: &Path,
|
|
||||||
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
|
||||||
f: &mut dyn FnMut(&DirEntry, &str),
|
|
||||||
) {
|
) {
|
||||||
let mut contents = Vec::new();
|
let mut contents = Vec::new();
|
||||||
walk_no_read(path, skip, &mut |entry| {
|
walk_no_read(paths, skip, &mut |entry| {
|
||||||
contents.clear();
|
contents.clear();
|
||||||
let mut file = t!(File::open(entry.path()), entry.path());
|
let mut file = t!(File::open(entry.path()), entry.path());
|
||||||
t!(file.read_to_end(&mut contents), entry.path());
|
t!(file.read_to_end(&mut contents), entry.path());
|
||||||
|
@ -67,11 +65,14 @@ pub fn walk(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn walk_no_read(
|
pub(crate) fn walk_no_read(
|
||||||
path: &Path,
|
paths: &[&Path],
|
||||||
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
||||||
f: &mut dyn FnMut(&DirEntry),
|
f: &mut dyn FnMut(&DirEntry),
|
||||||
) {
|
) {
|
||||||
let mut walker = ignore::WalkBuilder::new(path);
|
let mut walker = ignore::WalkBuilder::new(paths[0]);
|
||||||
|
for path in &paths[1..] {
|
||||||
|
walker.add(path);
|
||||||
|
}
|
||||||
let walker = walker.filter_entry(move |e| !skip(e.path()));
|
let walker = walker.filter_entry(move |e| !skip(e.path()));
|
||||||
for entry in walker.build() {
|
for entry in walker.build() {
|
||||||
if let Ok(entry) = entry {
|
if let Ok(entry) = entry {
|
||||||
|
|
Loading…
Add table
Reference in a new issue