MCPcopy Create free account
hub / github.com/devspace-sh/devspace / getWatchState

Method getWatchState

helper/server/downstream.go:265–303  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

263}
264
265func (d *Downstream) getWatchState() map[string]*remote.Change {
266 d.changesMutex.Lock()
267 defer d.changesMutex.Unlock()
268
269 var (
270 now = time.Now()
271 shouldRescan = d.watchedFiles == nil || d.lastRescan == nil || d.lastRescan.Add(rescanPeriod).Before(now)
272 changeAmount = len(d.changes)
273 )
274
275 if changeAmount > 100 || shouldRescan {
276 // we rescan so reset all changes
277 d.changes = map[string]bool{}
278 d.lastRescan = &now
279
280 newState := make(map[string]*remote.Change)
281 walkDir(d.options.RemotePath, d.options.RemotePath, d.ignoreMatcher, newState, d.options.NoRecursiveWatch, 0)
282 return newState
283 } else if changeAmount == 0 {
284 return nil
285 }
286
287 // copy state from old
288 newState := copyState(d.watchedFiles)
289
290 // copy changes
291 changes := []string{}
292 for k := range d.changes {
293 changes = append(changes, k)
294 }
295 d.changes = map[string]bool{}
296
297 // apply changes
298 for _, change := range changes {
299 d.applyChange(newState, change)
300 }
301
302 return newState
303}
304
305// Changes retrieves all changes from the watch path
306func (d *Downstream) Changes(empty *remote.Empty, stream remote.Downstream_ChangesServer) error {

Callers 1

ChangesMethod · 0.95

Calls 6

applyChangeMethod · 0.95
walkDirFunction · 0.85
copyStateFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected