From 65c22b10583009337303d01dd0785a5ebbe74ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=81=92?= <1091435068@qq.com> Date: Wed, 12 Aug 2015 15:26:50 +0800 Subject: [PATCH] make sure the h.file.Stat is the latest,oterwise the event value fileinfo is not the latest --- harvester.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/harvester.go b/harvester.go index ad09b931..2a8bc288 100644 --- a/harvester.go +++ b/harvester.go @@ -20,7 +20,7 @@ type Harvester struct { func (h *Harvester) Harvest(output chan *FileEvent) { h.open() - info, e := h.file.Stat() + _, e := h.file.Stat() if e != nil { panic(fmt.Sprintf("Harvest: unexpected error: %s", e.Error())) } @@ -52,11 +52,11 @@ func (h *Harvester) Harvest(output chan *FileEvent) { for { text, bytesread, err := h.readline(reader, buffer, read_timeout) + info, _ := h.file.Stat() if err != nil { if err == io.EOF { // timed out waiting for data, got eof. // Check to see if the file was truncated - info, _ := h.file.Stat() if info.Size() < h.Offset { emit("File truncated, seeking to beginning: %s\n", h.Path) h.file.Seek(0, os.SEEK_SET)