@@ -46,7 +46,7 @@ const (
4646// It polls the file system to detect modifications, truncations, deletions, or renames.
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.
49- func blockUntilEvent (ctx context.Context , f * os.File , pos int64 , cfg * Config ) (event , error ) {
49+ func blockUntilEvent (ctx context.Context , f * os.File , prevSize int64 , cfg * Config ) (event , error ) {
5050 origFi , err := os .Stat (cfg .Filename )
5151 if err != nil {
5252 // If file no longer exists we treat it as a delete event.
@@ -61,10 +61,8 @@ func blockUntilEvent(ctx context.Context, f *os.File, pos int64, cfg *Config) (e
6161 MaxBackoff : cfg .WatcherConfig .MaxPollFrequency ,
6262 })
6363
64- var (
65- prevSize = pos
66- prevModTime = origFi .ModTime ()
67- )
64+ prevModTime := origFi .ModTime ()
65+
6866 for backoff .Ongoing () {
6967 deletePending , err := fileext .IsDeletePending (f )
7068
@@ -104,7 +102,6 @@ func blockUntilEvent(ctx context.Context, f *os.File, pos int64, cfg *Config) (e
104102 if prevSize > 0 && prevSize < currentSize {
105103 return eventModified , nil
106104 }
107- prevSize = currentSize
108105
109106 // File was appended to (changed)?
110107 modTime := fi .ModTime ()
@@ -113,7 +110,7 @@ func blockUntilEvent(ctx context.Context, f *os.File, pos int64, cfg *Config) (e
113110 return eventModified , nil
114111 }
115112
116- // File hasn't changed; increase backoff for next sleep .
113+ // File hasn't changed so wait until next retry .
117114 backoff .Wait ()
118115 }
119116
0 commit comments