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

Method handleFileEvent

pkg/unpackerr/folder.go:458–493  ·  view source on GitHub ↗

handleFileEvent takes formatted events from fsnotify or fswatcher, does minimal (thread safe) validation before sending the re-formatted event to the main go routine.

(name, operation string)

Source from the content-addressed store, hash-verified

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.
458func (f *Folders) handleFileEvent(name, operation string) {
459 if strings.HasSuffix(name, suffix) {
460 return
461 }
462
463 // Send this event to processEvent().
464 for _, cnfg := range f.Config {
465 // Do not handle events on the watched folder itself.
466 if name == cnfg.Path {
467 return
468 }
469
470 // cnfg.Path: "/Users/Documents/watched_folder"
471 // event.Name: "/Users/Documents/watched_folder/new_folder/file.rar"
472 // eventData.name: "new_folder"
473 if !strings.HasPrefix(name, cnfg.Path) {
474 continue // Not the configured folder for the event we just got.
475 }
476
477 if cnfg.isExcludedPath(name) {
478 f.Debugf("Folder: Ignored event from excluded path: %v", name)
479 continue
480 }
481
482 // processEvent (below) handles events sent to f.Events.
483 if dir := filepath.Dir(name); dir == cnfg.Path {
484 f.Events <- &eventData{name: filepath.Base(name), cnfg: cnfg, file: name, op: operation}
485 } else {
486 f.Events <- &eventData{name: filepath.Base(dir), cnfg: cnfg, file: name, op: operation}
487 }
488
489 return
490 }
491
492 f.Debugf("Folder: Ignored event from non-configured path: %v", name)
493}
494
495// processEvent is here to process the event in the `*Unpackerr` scope before sending it back to the `*Folders` scope.
496func (u *Unpackerr) processEvent(event *eventData, now time.Time) {

Callers 2

watchFSNotifyMethod · 0.95

Calls 2

isExcludedPathMethod · 0.80
DebugfMethod · 0.65

Tested by 1