watchUpdate does the update for given path
(path string)
| 186 | |
| 187 | // watchUpdate does the update for given path |
| 188 | func (ft *Tree) watchUpdate(path string) { |
| 189 | ft.AsyncLock() |
| 190 | defer ft.AsyncUnlock() |
| 191 | // fmt.Println(path) |
| 192 | |
| 193 | dir, _ := filepath.Split(path) |
| 194 | rp := ft.RelativePathFrom(core.Filename(dir)) |
| 195 | if rp == ft.lastWatchUpdate { |
| 196 | now := time.Now() |
| 197 | lagMs := int(now.Sub(ft.lastWatchTime) / time.Millisecond) |
| 198 | if lagMs < 100 { |
| 199 | // fmt.Printf("skipping update to: %s due to lag: %v\n", rp, lagMs) |
| 200 | return // no update |
| 201 | } |
| 202 | } |
| 203 | fn, err := ft.findDirNode(rp) |
| 204 | if err != nil { |
| 205 | // slog.Error(err.Error()) |
| 206 | return |
| 207 | } |
| 208 | ft.lastWatchUpdate = rp |
| 209 | ft.lastWatchTime = time.Now() |
| 210 | if !fn.isOpen() { |
| 211 | // fmt.Printf("warning: watcher updating closed node: %s\n", rp) |
| 212 | return // shouldn't happen |
| 213 | } |
| 214 | fn.Update() |
| 215 | } |
| 216 | |
| 217 | // watchPath adds given path to those watched |
| 218 | func (ft *Tree) watchPath(path core.Filename) error { |
no test coverage detected