File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ func main() {
37
37
}
38
38
39
39
if n != 0 {
40
- config .LineLocation = & tail.SeekInfo {- n + 1 , io .SeekEnd }
40
+ config .LineLocation = & tail.SeekInfo {- n , io .SeekEnd }
41
41
}
42
42
43
43
done := make (chan bool )
Original file line number Diff line number Diff line change @@ -254,7 +254,28 @@ func (tail *Tail) tailFileSync() {
254
254
}
255
255
} else if tail .LineLocation != nil {
256
256
lineFile := fls .LineFile (tail .file )
257
- _ , err := lineFile .SeekLine (tail .LineLocation .Offset , tail .LineLocation .Whence )
257
+ buf := make ([]byte , 1 )
258
+
259
+ _ , err := lineFile .Seek (- 1 , io .SeekEnd )
260
+ if err != nil {
261
+ tail .Killf ("Seek error on %s: %s" , tail .Filename , err )
262
+ return
263
+ }
264
+
265
+ _ , err = lineFile .Read (buf )
266
+ if err != nil {
267
+ tail .Killf ("Seek error on %s: %s" , tail .Filename , err )
268
+ return
269
+ }
270
+
271
+ // if file ends in newline don't count it in lines
272
+ // to read from end (mimics unix tail command)
273
+ correction := int64 (1 )
274
+ if string (buf ) == "\n " {
275
+ correction = 0
276
+ }
277
+
278
+ _ , err = lineFile .SeekLine (tail .LineLocation .Offset + correction , tail .LineLocation .Whence )
258
279
if err != nil && err != io .EOF {
259
280
tail .Killf ("Seek error on %s: %s" , tail .Filename , err )
260
281
return
You can’t perform that action at this time.
0 commit comments