MCPcopy
hub / github.com/perkeep/perkeep / newIgnoreChecker

Function newIgnoreChecker

pkg/client/config.go:501–539  ·  view source on GitHub ↗

changed by tests newIgnoreChecker uses ignoredFiles to build and return a func that returns whether the file path argument should be ignored. See IsIgnoredFile for the ignore rules.

(ignoredFiles []string)

Source from the content-addressed store, hash-verified

499
500// newIgnoreChecker uses ignoredFiles to build and return a func that returns whether the file path argument should be ignored. See IsIgnoredFile for the ignore rules.
501func newIgnoreChecker(ignoredFiles []string) func(path string) (shouldIgnore bool) {
502 var fns []func(string) bool
503
504 // copy of ignoredFiles for us to mutate
505 ignFiles := append([]string(nil), ignoredFiles...)
506 for k, v := range ignFiles {
507 if strings.HasPrefix(v, filepath.FromSlash("~/")) {
508 ignFiles[k] = filepath.Join(osutilHomeDir(), v[2:])
509 }
510 }
511 // We cache the ignoredFiles patterns in 3 categories (not necessarily exclusive):
512 // 1) shell patterns
513 // 3) absolute paths
514 // 4) paths components
515 for _, pattern := range ignFiles {
516 pattern := pattern
517 _, err := filepath.Match(pattern, "whatever")
518 if err == nil {
519 fns = append(fns, func(v string) bool { return isShellPatternMatch(pattern, v) })
520 }
521 }
522 for _, pattern := range ignFiles {
523 pattern := pattern
524 if filepath.IsAbs(pattern) {
525 fns = append(fns, func(v string) bool { return hasDirPrefix(filepath.Clean(pattern), v) })
526 } else {
527 fns = append(fns, func(v string) bool { return hasComponent(filepath.Clean(pattern), v) })
528 }
529 }
530
531 return func(path string) bool {
532 for _, fn := range fns {
533 if fn(path) {
534 return true
535 }
536 }
537 return false
538 }
539}
540
541var filepathSeparatorString = string(filepath.Separator)
542

Callers 3

TestIgnoreMultiPatternFunction · 0.85
TestIsIgnoredFileFunction · 0.85
initIgnoredFilesMethod · 0.85

Calls 6

isShellPatternMatchFunction · 0.85
hasDirPrefixFunction · 0.85
hasComponentFunction · 0.85
HasPrefixMethod · 0.80
CleanMethod · 0.80
MatchMethod · 0.65

Tested by 2

TestIgnoreMultiPatternFunction · 0.68
TestIsIgnoredFileFunction · 0.68