refactor seek routine
This commit is contained in:
parent
555e6044ca
commit
c13cdd473c
16
tail.go
16
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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue