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 {
|
||||
|
|
Loading…
Reference in New Issue