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)
| 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. |
| 501 | func 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 | |
| 541 | var filepathSeparatorString = string(filepath.Separator) |
| 542 |