watchFSNotify reads file system events from a channel and processes them. This runs in its own go routine, and eventually sends the event back into the main routine.
()
| 431 | // watchFSNotify reads file system events from a channel and processes them. |
| 432 | // This runs in its own go routine, and eventually sends the event back into the main routine. |
| 433 | func (f *Folders) watchFSNotify() { |
| 434 | defer log.Println("Folder watcher routine exited. No longer watching any folders.") |
| 435 | |
| 436 | for { |
| 437 | select { |
| 438 | case err := <-f.Watcher.Error: |
| 439 | f.Errorf("watcher: %v", err) |
| 440 | case err := <-f.FSNotify.Errors: |
| 441 | f.Errorf("fsnotify: %v", err) |
| 442 | case event, ok := <-f.FSNotify.Events: |
| 443 | if !ok { |
| 444 | return |
| 445 | } |
| 446 | |
| 447 | f.handleFileEvent(event.Name, "f "+event.Op.String()) |
| 448 | case event := <-f.Watcher.Event: |
| 449 | f.handleFileEvent(event.Path, "w "+event.Op.String()) |
| 450 | case <-f.Watcher.Closed: |
| 451 | return |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | // handleFileEvent takes formatted events from fsnotify or fswatcher, does minimal |
| 457 | // (thread safe) validation before sending the re-formatted event to the main go routine. |
no test coverage detected