MCPcopy Create free account
hub / github.com/cogentcore/core / watchUpdate

Method watchUpdate

filetree/tree.go:188–215  ·  view source on GitHub ↗

watchUpdate does the update for given path

(path string)

Source from the content-addressed store, hash-verified

186
187// watchUpdate does the update for given path
188func (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
218func (ft *Tree) watchPath(path core.Filename) error {

Callers 1

watchWatcherMethod · 0.95

Calls 10

FilenameTypeAlias · 0.92
AsyncLockMethod · 0.80
AsyncUnlockMethod · 0.80
SplitMethod · 0.80
RelativePathFromMethod · 0.80
findDirNodeMethod · 0.80
UpdateMethod · 0.65
NowMethod · 0.45
SubMethod · 0.45
isOpenMethod · 0.45

Tested by

no test coverage detected