]> git.proxmox.com Git - pathpatterns.git/commitdiff
add MatchPattern::Literal
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 20 May 2020 10:14:16 +0000 (12:14 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 20 May 2020 10:14:16 +0000 (12:14 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/match_list.rs

index 504f85d69e3e476de3eaea55c6e05d94a3a40c38..7ca5c0dac959d3751d3b2a542b813b9829aaf1e7 100644 (file)
@@ -48,6 +48,9 @@ impl Default for MatchFlag {
 pub enum MatchPattern {
     /// A glob pattern.
     Pattern(crate::Pattern),
+
+    /// A literal match.
+    Literal(Vec<u8>),
 }
 
 impl From<crate::Pattern> for MatchPattern {
@@ -56,6 +59,12 @@ impl From<crate::Pattern> for MatchPattern {
     }
 }
 
+impl MatchPattern {
+    pub fn literal(literal: impl Into<Vec<u8>>) -> Self {
+        MatchPattern::Literal(literal.into())
+    }
+}
+
 /// A pattern can be used as an include or an exclude pattern. In a list of `MatchEntry`s, later
 /// patterns take precedence over earlier patterns and the order of includes vs excludes makes a
 /// difference.
@@ -234,6 +243,7 @@ impl MatchEntry {
     fn matches_path_exact_do(&self, path: &[u8]) -> bool {
         match &self.pattern {
             MatchPattern::Pattern(pattern) => pattern.matches(path),
+            MatchPattern::Literal(literal) => path == &literal[..],
         }
     }