Skip to content

Commit

Permalink
Match invalid globs as exact matches
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Szwedko <jesse@szwedko.me>
  • Loading branch information
jszwedko committed Jun 16, 2021
1 parent 7151523 commit 5344183
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/config/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,34 @@ fn expand_globs(config: &mut ConfigBuilder) {
}
}

enum InputMatcher {
Pattern(glob::Pattern),
String(String),
}

impl InputMatcher {
fn matches(&self, candidate: &str) -> bool {
use Matcher::*;

match self {
Pattern(pattern) => pattern.matches(candidate),
String(s) => s == candidate,
}
}
}

fn expand_globs_inner(inputs: &mut Vec<String>, name: &str, candidates: &[String]) {
let raw_inputs = std::mem::take(inputs);
for raw_input in raw_inputs {
match glob::Pattern::new(&raw_input) {
Ok(pattern) => {
for input in candidates {
if pattern.matches(input) && input != name {
inputs.push(input.clone())
}
}
}
Err(error) => {
error!(message = "Invalid glob pattern for input.", component_name = name, %error);
continue;
let matcher = glob::Pattern::new(&raw_input)
.map(InputMatcher::Pattern)
.unwrap_or_else(|error| {
warn!(message = "Invalid glob pattern for input.", component_name = name, %error);
InputMatcher::String(raw_input)
});
for input in candidates {
if matcher.matches(input) && input != name {
inputs.push(input.clone())
}
}
}
Expand Down

0 comments on commit 5344183

Please sign in to comment.