MCPcopy Index your code
hub / github.com/devspace-sh/devspace / walkDir

Function walkDir

helper/server/downstream.go:534–597  ·  view source on GitHub ↗
(basePath string, path string, ignoreMatcher ignoreparser.IgnoreParser, state map[string]*remote.Change, noRecursive bool, throttle time.Duration)

Source from the content-addressed store, hash-verified

532}
533
534func 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()),

Callers 4

ChangesCountMethod · 0.85
getWatchStateMethod · 0.85
ChangesMethod · 0.85
applyChangeMethod · 0.85

Calls 9

IsRecursiveSymlinkFunction · 0.92
NameMethod · 0.65
RequireFullScanMethod · 0.65
MatchesMethod · 0.65
InfoMethod · 0.45
IsDirMethod · 0.45
SizeMethod · 0.45
ModTimeMethod · 0.45
ModeMethod · 0.45

Tested by

no test coverage detected