in src/rust/engine/fs/src/glob_matching.rs [49:113]
fn directory_listing(
&self,
canonical_dir: Dir,
symbolic_path: PathBuf,
wildcard: Pattern,
exclude: &Arc<GitignoreStyleExcludes>,
) -> BoxFuture<Vec<PathStat>, E> {
// List the directory.
let context = self.clone();
let exclude = exclude.clone();
self
.scandir(canonical_dir)
.and_then(move |dir_listing| {
// Match any relevant Stats, and join them into PathStats.
future::join_all(
dir_listing
.0
.iter()
.filter(|stat| {
// Match relevant filenames.
stat
.path()
.file_name()
.map(|file_name| wildcard.matches_path(Path::new(file_name)))
.unwrap_or(false)
})
.filter_map(|stat| {
// Append matched filenames.
stat
.path()
.file_name()
.map(|file_name| symbolic_path.join(file_name))
.map(|symbolic_stat_path| (symbolic_stat_path, stat))
})
.map(|(stat_symbolic_path, stat)| {
// Canonicalize matched PathStats, and filter paths that are ignored by local excludes.
// Context ("global") ignore patterns are applied during `scandir`.
if exclude.is_ignored(&stat) {
future::ok(None).to_boxed()
} else {
match stat {
Stat::Link(l) => context.canonicalize(stat_symbolic_path, l.clone()),
Stat::Dir(d) => future::ok(Some(PathStat::dir(
stat_symbolic_path.to_owned(),
d.clone(),
)))
.to_boxed(),
Stat::File(f) => future::ok(Some(PathStat::file(
stat_symbolic_path.to_owned(),
f.clone(),
)))
.to_boxed(),
}
}
})
.collect::<Vec<_>>(),
)
})
.map(|path_stats| {
// See the note above.
path_stats.into_iter().filter_map(|pso| pso).collect()
})
.to_boxed()
}