This repository was archived by the owner on Aug 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package watcher
33import (
44 "context"
55 "fmt"
6+ "io/fs"
67 "os"
78 "path/filepath"
89 "time"
@@ -161,9 +162,34 @@ func (w *FileWatcher) handleEvent(event fsnotify.Event) {
161162 switch event .Op {
162163 case fsnotify .Create , fsnotify .Write :
163164 // Check if this is actually a file (not a directory)
164- if info , err := os .Stat (filePath ); err == nil && ! info .IsDir () {
165+ info , err := os .Stat (filePath )
166+ if err == nil && ! info .IsDir () {
165167 w .handler .OnFileChanged (filePath )
166168 }
169+ if err == nil && info .IsDir () {
170+ err := w .watcher .Add (filePath )
171+ if err != nil {
172+ w .log .Error ().Err (err ).Str ("path" , filePath ).Msg ("failed to add directory to watcher" )
173+ return
174+ }
175+ err = filepath .WalkDir (filePath , func (path string , d fs.DirEntry , err error ) error {
176+ if err != nil {
177+ return err
178+ }
179+ // Skip directories
180+ if d .IsDir () {
181+ return nil
182+ }
183+ w .handler .OnFileChanged (path )
184+
185+ return nil
186+ })
187+ if err != nil {
188+ w .log .Error ().Err (err ).Str ("path" , filePath ).Msg ("failed to walk directory" )
189+ return
190+ }
191+ }
192+
167193 case fsnotify .Rename , fsnotify .Remove :
168194 w .handler .OnFileDeleted (filePath )
169195 default :
You can’t perform that action at this time.
0 commit comments