|
|
@ -88,6 +88,7 @@ func Parse(file io.Reader) (*Rules, error) {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Ignore evaluates path against the rules in order. Evaluation stops when a match
|
|
|
|
// Ignore evaluates path against the rules in order. Evaluation stops when a match
|
|
|
|
// is found. Matching a negative rule will stop evaluation.
|
|
|
|
// is found. Matching a negative rule will stop evaluation.
|
|
|
|
|
|
|
|
// Ignore evaluates the file at the given path, and returns true if it should be ignored.
|
|
|
|
func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
|
|
|
|
func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
|
|
|
|
// Don't match on empty dirs.
|
|
|
|
// Don't match on empty dirs.
|
|
|
|
if path == "" {
|
|
|
|
if path == "" {
|
|
|
@ -100,22 +101,34 @@ func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
|
|
|
|
if path == "." || path == "./" {
|
|
|
|
if path == "." || path == "./" {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for symlink and ignore based on pattern
|
|
|
|
|
|
|
|
if fi.Mode()&os.ModeSymlink != 0 {
|
|
|
|
|
|
|
|
resolvedPath, err := filepath.EvalSymlinks(path)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Printf("Ignoring broken symlink: %s -> %s", path, resolvedPath) // Log and ignore broken symlink
|
|
|
|
|
|
|
|
return false // Skip this symlink and continue
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, p := range r.patterns {
|
|
|
|
for _, p := range r.patterns {
|
|
|
|
if p.match == nil {
|
|
|
|
if p.match == nil {
|
|
|
|
log.Printf("ignore: no matcher supplied for %q", p.raw)
|
|
|
|
log.Printf("ignore: no matcher supplied for %q", p.raw)
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// For negative rules, we need to capture and return non-matches,
|
|
|
|
|
|
|
|
// and continue for matches.
|
|
|
|
|
|
|
|
if p.negate {
|
|
|
|
|
|
|
|
if p.mustDir && !fi.IsDir() {
|
|
|
|
if p.mustDir && !fi.IsDir() {
|
|
|
|
return true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !p.match(path, fi) {
|
|
|
|
if p.match(resolvedPath, fi) {
|
|
|
|
|
|
|
|
log.Printf("Ignoring symlink path: %s", path)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
return false // Skip further evaluation for this symlink
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, p := range r.patterns {
|
|
|
|
|
|
|
|
if p.match == nil {
|
|
|
|
|
|
|
|
log.Printf("ignore: no matcher supplied for %q", p.raw)
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the rule is looking for directories, and this is not a directory,
|
|
|
|
// If the rule is looking for directories, and this is not a directory,
|
|
|
|