MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / glob_match

Function glob_match

crates/openshell-bootstrap/src/build.rs:393–428  ·  view source on GitHub ↗

Simple glob matching supporting `*`, `**`, and `?`. This is intentionally simple — it covers the common `.dockerignore` cases without pulling in a full glob crate. For complex patterns, Docker's own builder handles them during the build step anyway; this is just for reducing the context tar size.

(pattern: &str, path: &str, is_dir: bool)

Source from the content-addressed store, hash-verified

391/// builder handles them during the build step anyway; this is just for
392/// reducing the context tar size.
393fn glob_match(pattern: &str, path: &str, is_dir: bool) -> bool {
394 // Handle ** prefix (match any number of directories)
395 if let Some(rest) = pattern.strip_prefix("**/") {
396 // Match against the path itself and any suffix after a /
397 if glob_match(rest, path, is_dir) {
398 return true;
399 }
400 for (idx, _) in path.match_indices('/') {
401 if glob_match(rest, &path[idx + 1..], is_dir) {
402 return true;
403 }
404 }
405 return false;
406 }
407
408 // Handle pattern that is just a name (no slashes) — match against any
409 // path component or as a prefix directory match.
410 if !pattern.contains('/') {
411 // Match the final component of the path.
412 let basename = path.rsplit('/').next().unwrap_or(path);
413 if simple_glob_match(pattern, basename) {
414 return true;
415 }
416 // Also match as a directory prefix: pattern "node_modules" should
417 // match "node_modules/foo/bar".
418 if let Some(first) = path.split('/').next()
419 && simple_glob_match(pattern, first)
420 {
421 return true;
422 }
423 return false;
424 }
425
426 // Pattern contains slashes — match against the full path.
427 simple_glob_match(pattern, path) || (is_dir && path.starts_with(pattern.trim_end_matches('/')))
428}
429
430/// Match a simple glob pattern (with `*` and `?` but not `**`) against a string.
431fn simple_glob_match(pattern: &str, text: &str) -> bool {

Callers 1

is_ignoredFunction · 0.85

Calls 2

simple_glob_matchFunction · 0.85
nextMethod · 0.45

Tested by

no test coverage detected