pub struct IgnoreRules { /* private fields */ }Expand description
The patterns of a .dockerignore file, applied the way Docker applies them.
Each line is trimmed; a line starting with # is a comment and a blank line is skipped;
! makes an exception. The pattern is cleaned as Go’s filepath.Clean cleans it and a
leading / is dropped, so /foo, ./foo and foo/ all mean foo. A pattern matches a
path when it matches the path itself or any of its parent directories, so node_modules
excludes everything under it; the last line that matches decides, so a later ! line
re-includes.
The glob is Go’s filepath.Match plus **: * and ? stop at /, [...] is a
character class negated by ^ (not !, which is a member), \ escapes the next
character, **/ matches any number of directories including none, and a trailing **
matches anything. These are the semantics of moby’s patternmatcher, which
crates/microvms-core/tests/context_fuzz.rs checks against a rebuilt copy of its regex
translation.
Implementations§
Source§impl IgnoreRules
impl IgnoreRules
Sourcepub fn parse(text: &str) -> Result<Self, Error>
pub fn parse(text: &str) -> Result<Self, Error>
Parses a .dockerignore file’s text, refusing a line Docker would refuse: a bare
!, an unterminated [, or a class range that runs backwards.
Sourcepub fn excludes(&self, path: &str) -> bool
pub fn excludes(&self, path: &str) -> bool
Whether path — relative to the context root, /-separated — is excluded.
Sourcepub fn has_exceptions(&self) -> bool
pub fn has_exceptions(&self) -> bool
Whether any rule is an exception (!pattern), which is when an excluded directory
still has to be walked: an exception could bring something under it back.