@@ -510,35 +510,36 @@ func (w *inotify) handleEvent(inEvent *unix.InotifyEvent, buf *[65536]byte, offs
510510 w .watches .wd [k ] = ww
511511 }
512512 }
513- }
514- // Register a newly created dir tree
515- // This is for "mkdir -p one/two/three".
516- // Usually all those directories will be created before we can set up
517- // watchers on the subdirectories, so only "one" would be sent
518- // as a Create event and not "one/two" and "one/two/three"
519- // (inotifywait -r has the same problem).
520- err = filepath .WalkDir (ev .Name , func (curDir string , d fs.DirEntry , err error ) error {
521- if err != nil {
522- return err
523- }
513+ } else {
514+ // Register a newly created dir tree
515+ // This is for "mkdir -p one/two/three".
516+ // Usually all those directories will be created before we can set up
517+ // watchers on the subdirectories, so only "one" would be sent
518+ // as a Create event and not "one/two" and "one/two/three"
519+ // (inotifywait -r has the same problem).
520+ err = filepath .WalkDir (ev .Name , func (curDir string , d fs.DirEntry , err error ) error {
521+ if err != nil {
522+ return err
523+ }
524524
525- if ev .Name != curDir {
526- // Send artificial create event.
527- // We don't know what has really happened.
525+ if ev .Name != curDir {
526+ // Send artificial create event.
527+ // We don't know what has really happened.
528528
529- // Send the previous event first to maintain proper ordering, then create a new event for the current directory
530- // The function expects to return only one event, so we need to send the previous event first and then create a new one
531- w .sendEvent (ev )
532- ev = w .newEvent (curDir , unix .IN_CREATE , 0 )
533- }
529+ // Send the previous event first to maintain proper ordering, then create a new event for the current directory
530+ // The function expects to return only one event, so we need to send the previous event first and then create a new one
531+ w .sendEvent (ev )
532+ ev = w .newEvent (curDir , unix .IN_CREATE , 0 )
533+ }
534534
535- if d .IsDir () {
536- return w .register (curDir , watch .flags , flagRecurse )
535+ if d .IsDir () {
536+ return w .register (curDir , watch .flags , flagRecurse )
537+ }
538+ return nil
539+ })
540+ if ! w .sendError (err ) {
541+ return Event {}, false
537542 }
538- return nil
539- })
540- if ! w .sendError (err ) {
541- return Event {}, false
542543 }
543544 }
544545 }
0 commit comments