MCPcopy Create free account
hub / github.com/Unpackerr/unpackerr / watchFSNotify

Method watchFSNotify

pkg/unpackerr/folder.go:433–454  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

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.
433func (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.

Callers 1

PollFoldersMethod · 0.80

Calls 3

handleFileEventMethod · 0.95
ErrorfMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected