MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / matches_glob

Function matches_glob

atomic-repository/src/archive.rs:778–803  ·  view source on GitHub ↗

Simple glob pattern matching. Supports: - `*` matches any characters - `?` matches single character - Exact match

(path: &str, pattern: &str)

Source from the content-addressed store, hash-verified

776/// - `?` matches single character
777/// - Exact match
778fn matches_glob(path: &str, pattern: &str) -> bool {
779 if pattern == "*" {
780 return true;
781 }
782
783 if pattern.starts_with('*') && pattern.ends_with('*') && pattern.len() > 2 {
784 let inner = &pattern[1..pattern.len() - 1];
785 return path.contains(inner);
786 }
787
788 if let Some(suffix) = pattern.strip_prefix('*') {
789 return path.ends_with(suffix);
790 }
791
792 if let Some(prefix) = pattern.strip_suffix('*') {
793 return path.starts_with(prefix);
794 }
795
796 if let Some(prefix) = pattern.strip_suffix('/') {
797 // Directory pattern
798 return path.starts_with(prefix)
799 && (path.len() == prefix.len() || path[prefix.len()..].starts_with('/'));
800 }
801
802 path == pattern
803}
804
805/// Ensure a path ends with the appropriate extension for the format.
806pub fn ensure_extension(path: &Path, format: ArchiveFormat) -> PathBuf {

Callers 1

should_includeMethod · 0.85

Calls 2

lenMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected