Skip to content

Commit 58502fe

Browse files
committed
enhance(cache): handle symlinks in file event handler
1 parent e7e15bb commit 58502fe

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

internal/cache/index.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,28 @@ func (s *Scanner) handleFileEvent(event fsnotify.Event) {
216216
return
217217
}
218218

219-
fi, err := os.Stat(event.Name)
219+
// Use Lstat to get symlink info without following it
220+
fi, err := os.Lstat(event.Name)
220221
if err != nil {
221222
return
222223
}
223224

224-
if fi.IsDir() {
225+
// If it's a symlink, we need to check what it points to
226+
var targetIsDir bool
227+
if fi.Mode()&os.ModeSymlink != 0 {
228+
// For symlinks, check the target
229+
targetFi, err := os.Stat(event.Name)
230+
if err != nil {
231+
logger.Debug("Symlink target not accessible:", event.Name, err)
232+
return
233+
}
234+
targetIsDir = targetFi.IsDir()
235+
logger.Debug("Symlink changed:", event.Name, "-> target is dir:", targetIsDir)
236+
} else {
237+
targetIsDir = fi.IsDir()
238+
}
239+
240+
if targetIsDir {
225241
logger.Debug("Directory changed:", event.Name)
226242
} else {
227243
logger.Debug("File changed:", event.Name)

0 commit comments

Comments
 (0)