add MatchPattern::Literal

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-05-20 12:14:16 +02:00
parent e2255d72d1
commit e86ed76048

View 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[..],
}
}