From b19a73593361829b366a4400d3936420c4c6f0ed Mon Sep 17 00:00:00 2001 From: Mark Martin Date: Tue, 15 Nov 2016 11:30:14 -0800 Subject: [PATCH] Update the tailing library to fix tailing stops for truncated files (#190) --- .../papertrail/go-tail/follower/follower.go | 27 ++++++++++--------- vendor/vendor.json | 12 ++++++--- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/vendor/github.com/papertrail/go-tail/follower/follower.go b/vendor/github.com/papertrail/go-tail/follower/follower.go index 8347d3b..0c33efd 100644 --- a/vendor/github.com/papertrail/go-tail/follower/follower.go +++ b/vendor/github.com/papertrail/go-tail/follower/follower.go @@ -41,7 +41,6 @@ type Follower struct { err error config Config reader *bufio.Reader - dangle int closeCh chan struct{} } @@ -115,14 +114,16 @@ func (t *Follower) follow() error { if err == io.EOF { l := len(s) - t.file.Seek(-int64(l), io.SeekCurrent) + _, err := t.file.Seek(-int64(l), io.SeekCurrent) + if err != nil { + return err + } + t.reader.Reset(t.file) - t.dangle += l break } - t.dangle = 0 t.sendLine(s) } @@ -135,6 +136,16 @@ func (t *Follower) follow() error { case fsnotify.Write: continue + // truncated. seek to the end minus any dangling bytes before linebreak + case fsnotify.Chmod: + _, err = t.file.Seek(0, io.SeekStart) + if err != nil { + return err + } + + t.reader.Reset(t.file) + continue + // if a file is removed or renamed // and re-opening is desired, see if it appears // again within a 1 second deadline. this should be enough time @@ -151,14 +162,6 @@ func (t *Follower) follow() error { return err } - // if we received a CHMOD and have reopened the file, - // seek to the end minus any dangling bytes before linebreak - if evt.Op == fsnotify.Chmod { - if _, err := t.file.Seek(-int64(t.dangle), io.SeekEnd); err != nil { - return err - } - } - watcher.Add(t.filename) continue } diff --git a/vendor/vendor.json b/vendor/vendor.json index 358e62b..da55a71 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -108,10 +108,16 @@ "revision": "b30dcbfa86e3a1eaa4e6622de2ce57be2c138c10" }, { - "checksumSHA1": "lzmC5x+0g8P0WwiBY68mlmCaSqc=", + "checksumSHA1": "2aD8Ll16aJCh32lm09ow88q0BO4=", + "path": "github.com/papertrail/go-tail", + "revision": "c08f359f0f47b6a0a603b526a012fcc8924a65b0", + "revisionTime": "2016-11-15T00:28:15Z" + }, + { + "checksumSHA1": "bxKDUFzzl81g5apnjRKVr5e0Cw4=", "path": "github.com/papertrail/go-tail/follower", - "revision": "78f0657870da1622fe4ca1dce85805c7c1f4d455", - "revisionTime": "2016-11-05T01:59:04Z" + "revision": "c08f359f0f47b6a0a603b526a012fcc8924a65b0", + "revisionTime": "2016-11-15T00:28:15Z" }, { "checksumSHA1": "8Y05Pz7onrQPcVWW6JStSsYRh6E=",