(stopChan chan struct{})
| 326 | } |
| 327 | |
| 328 | func (d *Downstream) watch(stopChan chan struct{}) { |
| 329 | for { |
| 330 | select { |
| 331 | case <-stopChan: |
| 332 | return |
| 333 | case event, ok := <-d.events: |
| 334 | if !ok { |
| 335 | return |
| 336 | } |
| 337 | |
| 338 | d.changesMutex.Lock() |
| 339 | // re-sync if overflow |
| 340 | if len(d.events) >= 999 { |
| 341 | d.lastRescan = nil |
| 342 | } else { |
| 343 | // check if parent folder might be already in changes then skip |
| 344 | // this saves us a lot of folder crawling later on |
| 345 | parts := strings.Split(filepath.ToSlash(event.Path()), "/") |
| 346 | found := false |
| 347 | for i := len(parts) - 1; i > 0; i-- { |
| 348 | path := strings.Join(parts[:i], "/") |
| 349 | if d.changes[path] { |
| 350 | found = true |
| 351 | break |
| 352 | } |
| 353 | } |
| 354 | if !found { |
| 355 | d.changes[event.Path()] = true |
| 356 | } |
| 357 | } |
| 358 | d.changesMutex.Unlock() |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | func (d *Downstream) applyChange(newState map[string]*remote.Change, fullPath string) { |
| 364 | fullPath = strings.TrimSuffix(fullPath, "/") |
no test coverage detected