(event fsnotify.Event, path string, watcherCache types.EditorWatcherCache)
| 67 | } |
| 68 | |
| 69 | func 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 | |
| 98 | func sendFullContent(path string) { |
| 99 | content, err := os.ReadFile(path) |
no test coverage detected