MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / walkDir

Function walkDir

cache/utils.go:10–41  ·  view source on GitHub ↗

walkDir calls f on all the cache files in the given dir.

(dir string, f func(fi os.FileInfo))

Source from the content-addressed store, hash-verified

8
9// walkDir calls f on all the cache files in the given dir.
10func walkDir(dir string, f func(fi os.FileInfo)) error {
11 // Do not use filepath.Walk, since it is inefficient
12 // for large number of files.
13 // See https://golang.org/pkg/path/filepath/#Walk .
14 fd, err := os.Open(dir)
15 if err != nil {
16 return fmt.Errorf("cannot open %q: %w", dir, err)
17 }
18 defer fd.Close()
19
20 for {
21 fis, err := fd.Readdir(1024)
22 if err != nil {
23 if err == io.EOF {
24 return nil
25 }
26 return fmt.Errorf("cannot read files in %q: %w", dir, err)
27 }
28 for _, fi := range fis {
29 if fi.IsDir() {
30 // Skip subdirectories
31 continue
32 }
33 fn := fi.Name()
34 if !cachefileRegexp.MatchString(fn) {
35 // Skip invalid filenames
36 continue
37 }
38 f(fi)
39 }
40 }
41}

Callers 1

cleanMethod · 0.85

Calls 2

NameMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected