diff --git a/tail.go b/tail.go index 8d87d32..482ca88 100644 --- a/tail.go +++ b/tail.go @@ -231,13 +231,11 @@ func (tail *Tail) tailFileSync() { case <-tail.Dying(): return } - _, err := tail.file.Seek(0, 2) // Seek to fine end + err = tail.seekEnd() if err != nil { - tail.Killf("Seek error on %s: %s", tail.Filename, err) + tail.Kill(err) return } - // Reset the read buffer whenever the file is re-seek'ed - tail.reader.Reset(tail.file) } } case io.EOF: @@ -321,6 +319,16 @@ func (tail *Tail) newReader() *bufio.Reader { } } +func (tail *Tail) seekEnd() error { + _, err := tail.file.Seek(0, 2) + if err != nil { + return fmt.Errorf("Seek error on %s: %s", tail.Filename, err) + } + // Reset the read buffer whenever the file is re-seek'ed + tail.reader.Reset(tail.file) + return nil +} + // sendLine sends the line(s) to Lines channel, splitting longer lines // if necessary. Return false if rate limit is reached. func (tail *Tail) sendLine(line []byte) bool { diff --git a/tail_test.go b/tail_test.go index 219aacc..58b340a 100644 --- a/tail_test.go +++ b/tail_test.go @@ -268,7 +268,7 @@ func TestRateLimiting(_t *testing.T) { // TODO: also verify that tail resumes after the cooloff period. go t.VerifyTailOutput( - tail, + tail, []string{"hello", "world", "again", expecting, "more", "data"}) // Add more data only after reasonable delay.