MCPcopy Create free account
hub / github.com/MertJSX/folderhost / SetupWatcher

Function SetupWatcher

middleware/websocket/file_watcher.go:28–67  ·  view source on GitHub ↗
(path string, stopChan chan bool)

Source from the content-addressed store, hash-verified

26}
27
28func SetupWatcher(path string, stopChan chan bool) {
29 watcher, err := fsnotify.NewWatcher()
30 if err != nil {
31 log.Println("Watcher creation error:", err)
32 return
33 }
34 defer watcher.Close()
35 defer close(stopChan)
36
37 err = watcher.Add(path)
38 if err != nil {
39 log.Println("Watcher add error:", err)
40 return
41 }
42
43 // On file changed by the host computer
44 for {
45 select {
46 case event, ok := <-watcher.Events:
47 if !ok {
48 return
49 }
50 watcherCache, ok := cache.EditorWatcherCache.Get(path)
51 if !ok {
52 return
53 }
54 onFileChanged(event, path, watcherCache)
55
56 case _, ok := <-watcher.Errors:
57 if !ok {
58 return
59 }
60
61 case <-stopChan:
62 // Watcher received stop signal
63 return
64 }
65 }
66
67}
68
69func onFileChanged(event fsnotify.Event, path string, watcherCache types.EditorWatcherCache) {
70 if !event.Has(fsnotify.Write) {

Callers 1

HandleWebsocketFunction · 0.85

Calls 2

onFileChangedFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected