only add to watchlist if open is successful

This commit is contained in:
Alexander Wang 2023-11-10 14:36:28 -08:00
parent 84a647d6d1
commit 05fd80d4c5
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE

View file

@ -648,12 +648,15 @@ func wsHeartbeat(ctx context.Context, c *websocket.Conn) {
}
}
// trackedFS is OS's FS with the addition that it tracks which files are opened
// trackedFS is OS's FS with the addition that it tracks which files are opened successfully
type trackedFS struct {
opened []string
}
func (tfs *trackedFS) Open(name string) (fs.File, error) {
tfs.opened = append(tfs.opened, name)
return os.Open(name)
f, err := os.Open(name)
if err == nil {
tfs.opened = append(tfs.opened, name)
}
return f, err
}