From 8d78912e0c7c0e70d284b12214bed242dd155dc3 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 25 Oct 2024 17:41:43 +0200 Subject: [PATCH] expand patterns in `GlobEntry` --- crates/oxide/src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/oxide/src/lib.rs b/crates/oxide/src/lib.rs index b45767c0b..32ea52fba 100644 --- a/crates/oxide/src/lib.rs +++ b/crates/oxide/src/lib.rs @@ -1,5 +1,6 @@ use crate::parser::Extractor; use crate::scanner::detect_sources::DetectSources; +use bexpand::Expression; use bstr::ByteSlice; use fxhash::{FxHashMap, FxHashSet}; use glob::fast_glob; @@ -217,6 +218,26 @@ impl Scanner { return; } + // Expand glob patterns and create new `GlobEntry` instances for each expanded pattern. + let sources = sources + .iter() + .flat_map(|source| { + let expression: Result = source.pattern[..].try_into(); + let Ok(expression) = expression else { + return vec![source.clone()]; + }; + + expression + .into_iter() + .filter_map(|expanded_pattern| expanded_pattern.map(|x| x.into()).ok()) + .map(move |pattern| GlobEntry { + base: source.base.clone(), + pattern, + }) + .collect::>() + }) + .collect::>(); + // Partition sources into sources that should be promoted to auto source detection and // sources that should be resolved as globs. let (auto_sources, glob_sources): (Vec<_>, Vec<_>) = sources.iter().partition(|source| {