Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions follower/follower.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"time"

"github.com/elastic/beats/libbeat/common/file"
"github.com/fsnotify/fsnotify"
)

Expand Down Expand Up @@ -264,7 +265,7 @@ func (t *Follower) reopen() error {
t.file = nil
}

file, err := os.Open(t.filename)
file, err := file.ReadOpen(t.filename)
if err != nil {
return err
}
Expand All @@ -286,7 +287,13 @@ func (t *Follower) close(err error) {
}

func (t *Follower) sendLine(l []byte, d int) {
t.lines <- Line{l[:len(l)-1], d}
// on Windows line usually ends with \r\n, so set offset to \r\n when it exists
offset := 1
if len(l) >= 2 && l[len(l)-2] == '\r' {
offset = 2
}

t.lines <- Line{l[:len(l)-offset], d}
}

func (t *Follower) watchFileEvents(eventChan chan fsnotify.Event, errChan chan error) {
Expand Down
4 changes: 2 additions & 2 deletions follower/follower_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package follower

import (
"fmt"
"log"
"io"
"io/ioutil"
"log"
"os"
"path"
"runtime"
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestMain(m *testing.M) {
os.RemoveAll(tmpDir)
if rs == 0 {
// Followers may take 10 seconds to notice the removal.
time.Sleep(10 * time.Second)
time.Sleep(11 * time.Second)
if runtime.NumGoroutine() > 2 {
// Heuristic to detect leaked goroutines.
fmt.Println("--- FAIL: TestMain")
Expand Down