From 53a46b4e2a038acbc6cbaa1d524bd0fb786e49c3 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Thu, 18 Dec 2025 10:06:43 -0700 Subject: [PATCH] use globset crate for find functionality --- signal-gateway-code-tool/src/lib.rs | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/signal-gateway-code-tool/src/lib.rs b/signal-gateway-code-tool/src/lib.rs index 0c58438..9fe29bc 100644 --- a/signal-gateway-code-tool/src/lib.rs +++ b/signal-gateway-code-tool/src/lib.rs @@ -360,21 +360,21 @@ impl CodeTool { /// Find files matching a glob pattern (like `find`). /// - /// Supports simple glob patterns with `*` wildcards. + /// Supports glob patterns using the `globset` crate syntax. pub async fn find(&self, pattern: Option<&str>) -> Result { let cache = self.get_current_tarball().await; let cached = cache.as_ref().ok_or("source code not available")?; let pattern = pattern.unwrap_or("*"); - // Convert glob pattern to regex - let regex_pattern = glob_to_regex(pattern); - let regex = Regex::new(®ex_pattern).map_err(|e| format!("Invalid pattern: {e}"))?; + let glob = Glob::new(pattern) + .map_err(|e| format!("Invalid glob pattern: {e}"))? + .compile_matcher(); let mut matches: Vec<&str> = cached .files .keys() - .filter(|path| regex.is_match(path)) + .filter(|path| glob.is_match(path)) .map(|s| s.as_str()) .collect(); @@ -548,24 +548,6 @@ impl CodeTool { } } -/// Convert a simple glob pattern to a regex. -fn glob_to_regex(pattern: &str) -> String { - let mut regex = String::from("^"); - for c in pattern.chars() { - match c { - '*' => regex.push_str(".*"), - '?' => regex.push('.'), - '.' | '+' | '(' | ')' | '[' | ']' | '{' | '}' | '^' | '$' | '|' | '\\' => { - regex.push('\\'); - regex.push(c); - } - _ => regex.push(c), - } - } - regex.push('$'); - regex -} - /// Check if content looks like binary data. fn looks_binary(content: &str) -> bool { // Check first 1000 chars for null bytes or high ratio of non-printable chars