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

Function onFileChanged

middleware/websocket/file_watcher.go:69–96  ·  view source on GitHub ↗
(event fsnotify.Event, path string, watcherCache types.EditorWatcherCache)

Source from the content-addressed store, hash-verified

67}
68
69func onFileChanged(event fsnotify.Event, path string, watcherCache types.EditorWatcherCache) {
70 if !event.Has(fsnotify.Write) {
71 return
72 }
73
74 if watcherCache.IsWriting {
75 return
76 }
77
78 info, err := os.Stat(path)
79
80 if err != nil {
81 return
82 }
83
84 if info.ModTime() != watcherCache.LastModTime {
85 // file changed by host computer
86 // fmt.Println("File changed by host PC!")
87 watcherCache.LastModTime = info.ModTime()
88 cache.EditorWatcherCache.SetWithoutTTL(path, watcherCache)
89 // Send full content if filesize is lower than 200 KB
90 if info.Size() < 200*1024 {
91 sendFullContent(path)
92 } else {
93 sendReloadNotification(path)
94 }
95 }
96}
97
98func sendFullContent(path string) {
99 content, err := os.ReadFile(path)

Callers 1

SetupWatcherFunction · 0.85

Calls 3

sendFullContentFunction · 0.85
sendReloadNotificationFunction · 0.85
SetWithoutTTLMethod · 0.80

Tested by

no test coverage detected