@@ -5,6 +5,7 @@ package unpackerr
55import (
66 "errors"
77 "fmt"
8+ "log"
89 "os"
910 "path/filepath"
1011 "strings"
@@ -318,6 +319,8 @@ func mapLen(in map[string][]string) (out int) {
318319
319320// watchFSNotify reads file system events from a channel and processes them.
320321func (f * Folders ) watchFSNotify () {
322+ defer log .Println ("Folder watcher routine exited. No longer watching any folders." )
323+
321324 for {
322325 select {
323326 case err := <- f .Watcher .Error :
@@ -330,12 +333,10 @@ func (f *Folders) watchFSNotify() {
330333 }
331334
332335 f .handleFileEvent (event .Name , "f " + event .Op .String ())
333- case event , ok := <- f .Watcher .Event :
334- if ! ok {
335- return
336- }
337-
338- f .handleFileEvent (event .Name (), "w " + event .Op .String ())
336+ case event := <- f .Watcher .Event :
337+ f .handleFileEvent (event .Path , "w " + event .Op .String ())
338+ case <- f .Watcher .Closed :
339+ return
339340 }
340341 }
341342}
@@ -352,12 +353,18 @@ func (f *Folders) handleFileEvent(name, operation string) {
352353 // eventData.name: "new_folder"
353354 if ! strings .HasPrefix (name , cnfg .Path ) || name == cnfg .Path {
354355 continue // Not the configured folder for the event we just got.
355- } else if p := filepath .Dir (name ); p == cnfg .Path {
356+ }
357+
358+ if p := filepath .Dir (name ); p == cnfg .Path {
356359 f .Events <- & eventData {name : filepath .Base (name ), cnfg : cnfg , file : name , op : operation }
357360 } else {
358361 f .Events <- & eventData {name : filepath .Base (p ), cnfg : cnfg , file : name , op : operation }
359362 }
363+
364+ return
360365 }
366+
367+ f .Debugf ("Folder: Ignored event from non-configured path: %v" , name )
361368}
362369
363370// processEvent processes the event that was received.
0 commit comments