(basePath string, path string, ignoreMatcher ignoreparser.IgnoreParser, state map[string]*remote.Change, noRecursive bool, throttle time.Duration)
| 532 | } |
| 533 | |
| 534 | func walkDir(basePath string, path string, ignoreMatcher ignoreparser.IgnoreParser, state map[string]*remote.Change, noRecursive bool, throttle time.Duration) { |
| 535 | files, err := os.ReadDir(path) |
| 536 | if err != nil { |
| 537 | // We ignore errors here |
| 538 | return |
| 539 | } |
| 540 | |
| 541 | for _, dirEntry := range files { |
| 542 | f, err := dirEntry.Info() |
| 543 | if err != nil { |
| 544 | continue |
| 545 | } |
| 546 | |
| 547 | absolutePath := filepath.Join(path, f.Name()) |
| 548 | if fsutil.IsRecursiveSymlink(f, absolutePath) { |
| 549 | continue |
| 550 | } |
| 551 | |
| 552 | // Stat is necessary here, because readdir does not follow symlinks and |
| 553 | // IsDir() returns false for symlinked folders |
| 554 | stat, err := os.Stat(absolutePath) |
| 555 | if err != nil { |
| 556 | // Woops file is not here anymore -> ignore error |
| 557 | continue |
| 558 | } |
| 559 | |
| 560 | // Check if ignored |
| 561 | if ignoreMatcher != nil && !ignoreMatcher.RequireFullScan() && ignoreMatcher.Matches(absolutePath[len(basePath):], stat.IsDir()) { |
| 562 | continue |
| 563 | } |
| 564 | |
| 565 | // should throttle? |
| 566 | if throttle != 0 && len(state)%100 == 0 { |
| 567 | time.Sleep(throttle) |
| 568 | } |
| 569 | |
| 570 | // Check if directory |
| 571 | if stat.IsDir() { |
| 572 | // Check if not ignored |
| 573 | if ignoreMatcher == nil || !ignoreMatcher.RequireFullScan() || !ignoreMatcher.Matches(absolutePath[len(basePath):], true) { |
| 574 | state[absolutePath] = &remote.Change{ |
| 575 | Path: absolutePath, |
| 576 | IsDir: true, |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | if !noRecursive { |
| 581 | walkDir(basePath, absolutePath, ignoreMatcher, state, noRecursive, throttle) |
| 582 | } |
| 583 | } else { |
| 584 | // Check if not ignored |
| 585 | if ignoreMatcher == nil || !ignoreMatcher.RequireFullScan() || !ignoreMatcher.Matches(absolutePath[len(basePath):], false) { |
| 586 | state[absolutePath] = &remote.Change{ |
| 587 | Path: absolutePath, |
| 588 | Size: stat.Size(), |
| 589 | MtimeUnix: stat.ModTime().Unix(), |
| 590 | MtimeUnixNano: stat.ModTime().UnixNano(), |
| 591 | Mode: uint32(stat.Mode()), |
no test coverage detected