Simple glob pattern matching. Supports: - `*` matches any characters - `?` matches single character - Exact match
(path: &str, pattern: &str)
| 776 | /// - `?` matches single character |
| 777 | /// - Exact match |
| 778 | fn 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. |
| 806 | pub fn ensure_extension(path: &Path, format: ArchiveFormat) -> PathBuf { |
no test coverage detected