MCPcopy
hub / github.com/spicetify/cli / WatchRecursive

Function WatchRecursive

src/utils/watcher.go:50–82  ·  view source on GitHub ↗

WatchRecursive .

(root string, callbackEach func(fileName string, err error), callbackAfter func())

Source from the content-addressed store, hash-verified

48
49// WatchRecursive .
50func WatchRecursive(root string, callbackEach func(fileName string, err error), callbackAfter func()) {
51 var cache = map[string][]byte{}
52
53 for {
54 finalCallback := false
55
56 filepath.WalkDir(root, func(filePath string, info os.DirEntry, _ error) error {
57 if info.IsDir() {
58 return nil
59 }
60
61 curr, err := os.ReadFile(filePath)
62 if err != nil {
63 callbackEach(filePath, err)
64 return nil
65 }
66
67 if !bytes.Equal(cache[filePath], curr) {
68 callbackEach(filePath, nil)
69 cache[filePath] = curr
70 finalCallback = true
71 }
72
73 return nil
74 })
75
76 if callbackAfter != nil && finalCallback {
77 callbackAfter()
78 }
79
80 time.Sleep(INTERVAL)
81 }
82}
83
84type debugger struct {
85 Description string

Callers 1

WatchFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected