1use crate::parser::FilePatternOptions;
2use std::{ffi::OsStr, fs, io, path::PathBuf};
3use wildmatch::WildMatch;
4
5pub fn get_files(
6 root: &str,
7 file_pattern_options: &FilePatternOptions,
8) -> io::Result<Vec<PathBuf>> {
9 let mut result = vec![];
10
11 for path in fs::read_dir(root)? {
12 let path = path?.path();
13 if let Some("trt") = path.extension().and_then(OsStr::to_str) {
14 result.push(path.to_owned());
15 }
16 }
17
18 let skips = get_exclude_patterns(file_pattern_options);
19
20 result.retain(|path| {
22 !skips
23 .iter()
24 .map(|pattern| pattern.matches(&path.to_str().unwrap()))
25 .any(|op| op)
26 });
27
28 Ok(result)
29}
30
31fn get_exclude_patterns(file_pattern_options: &FilePatternOptions) -> Vec<WildMatch> {
32 let mut exclude_patterns: Vec<WildMatch> = Vec::new();
33 for pattern in &file_pattern_options.exclude_patterns {
34 exclude_patterns.push(WildMatch::new(&pattern));
35 }
36 exclude_patterns
37}