@@ -82,6 +82,7 @@ func retryWatching(watchPattern *watchPattern) {
8282 failureMu .Lock ()
8383 defer failureMu .Unlock ()
8484 if watchPattern .failureCount >= maxFailureCount {
85+ logger .Warn ("gave up watching" , zap .String ("dir" , watchPattern .dir ))
8586 return
8687 }
8788 logger .Info ("watcher was closed prematurely, retrying..." , zap .String ("dir" , watchPattern .dir ))
@@ -152,17 +153,28 @@ func stopSession(session C.uintptr_t) {
152153}
153154
154155//export go_handle_file_watcher_event
155- func go_handle_file_watcher_event (path * C.char , eventType C.int , pathType C.int , handle C.uintptr_t ) {
156+ func go_handle_file_watcher_event (path * C.char , associatedPath * C. char , eventType C.int , pathType C.int , handle C.uintptr_t ) {
156157 watchPattern := cgo .Handle (handle ).Value ().(* watchPattern )
157- goPath := C .GoString (path )
158+ handleWatcherEvent (watchPattern , C .GoString (path ), C .GoString (associatedPath ), int (eventType ), int (pathType ))
159+ }
160+
161+ func handleWatcherEvent (watchPattern * watchPattern , path string , associatedPath string , eventType int , pathType int ) {
162+ // If the watcher prematurely sends the die@ event, retry watching
163+ if pathType == 4 && strings .HasPrefix (path , "e/self/die@" ) && watcherIsActive .Load () {
164+ retryWatching (watchPattern )
165+ return
166+ }
158167
159- if watchPattern .allowReload (goPath , int ( eventType ), int ( pathType ) ) {
168+ if watchPattern .allowReload (path , eventType , pathType ) {
160169 watchPattern .trigger <- struct {}{}
170+ return
161171 }
162172
163- // If the watcher prematurely sends the die@ event, retry watching
164- if pathType == 4 && strings .HasPrefix (goPath , "e/self/die@" ) && watcherIsActive .Load () {
165- retryWatching (watchPattern )
173+ // some editors create temporary files and never actually modify the original file
174+ // so we need to also check the associated path of an event
175+ // see https://github.com/dunglas/frankenphp/issues/1375
176+ if associatedPath != "" && watchPattern .allowReload (associatedPath , eventType , pathType ) {
177+ watchPattern .trigger <- struct {}{}
166178 }
167179}
168180
0 commit comments