refactor seek routine

This commit is contained in:
Sridhar Ratnakumar 2014-04-28 14:55:51 -07:00
parent 555e6044ca
commit c13cdd473c
2 changed files with 13 additions and 5 deletions

16
tail.go
View File

@ -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 {