Skip to content

Commit 65242e3

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

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

api/analytic/analytic.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func Analytic(c *gin.Context) {
9494

9595
select {
9696
case <-kernel.Context.Done():
97+
logger.Debug("Analytic: Context cancelled, closing WebSocket")
9798
return
9899
case <-time.After(1 * time.Second):
99100
}

api/analytic/nodes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func GetNodeStat(c *gin.Context) {
8686

8787
select {
8888
case <-kernel.Context.Done():
89+
logger.Debug("GetNodeStat: Context cancelled, closing WebSocket")
8990
return
9091
case <-time.After(10 * time.Second):
9192
}
@@ -119,6 +120,7 @@ func GetNodesAnalytic(c *gin.Context) {
119120

120121
select {
121122
case <-kernel.Context.Done():
123+
logger.Debug("GetNodesAnalytic: Context cancelled, closing WebSocket")
122124
return
123125
case <-time.After(10 * time.Second):
124126
}

api/event/websocket.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ func (c *Client) writePump() {
179179
return
180180

181181
case <-kernel.Context.Done():
182+
logger.Debug("EventBus: Context cancelled, closing WebSocket")
182183
return
183184
}
184185
}

api/nginx/websocket.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (h *NginxPerformanceHub) run() {
8080
h.broadcastPerformanceData()
8181

8282
case <-kernel.Context.Done():
83+
logger.Debug("NginxPerformanceHub: Context cancelled, closing WebSocket")
8384
// Shutdown all clients
8485
h.mutex.Lock()
8586
for client := range h.clients {
@@ -200,6 +201,7 @@ func (c *NginxPerformanceClient) writePump() {
200201
return
201202

202203
case <-kernel.Context.Done():
204+
logger.Debug("NginxPerformanceClient: Context cancelled, closing WebSocket")
203205
return
204206
}
205207
}

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)