Skip to content

Commit 24f6396

Browse files
committed
stat open file so we get correct comparison
1 parent 01f2411 commit 24f6396

File tree

1 file changed

+3
-2
lines changed
  • internal/component/loki/source/file/internal/tail

1 file changed

+3
-2
lines changed

internal/component/loki/source/file/internal/tail/block.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ const (
4747
// The pos parameter is the current file position and is used to detect truncation events.
4848
// Returns the detected event type and any error encountered. Returns eventNone if the context is canceled.
4949
func blockUntilEvent(ctx context.Context, f *os.File, prevSize int64, cfg *Config) (event, error) {
50-
origFi, err := os.Stat(cfg.Filename)
50+
// NOTE: it is important that we stat the open file here. Later we do os.Stat(cfg.Filename)
51+
// and use os.IsSameFile to detect if file was rotated.
52+
origFi, err := f.Stat()
5153
if err != nil {
5254
// If file no longer exists we treat it as a delete event.
5355
if os.IsNotExist(err) {
@@ -106,7 +108,6 @@ func blockUntilEvent(ctx context.Context, f *os.File, prevSize int64, cfg *Confi
106108
// File was appended to (changed)?
107109
modTime := fi.ModTime()
108110
if modTime != prevModTime {
109-
prevModTime = modTime
110111
return eventModified, nil
111112
}
112113

0 commit comments

Comments
 (0)