support Follow=false

This commit is contained in:
Sridhar Ratnakumar 2013-05-30 13:18:46 -07:00
parent 92ad722d56
commit f461ddc97d
3 changed files with 18 additions and 4 deletions

View File

@ -5,6 +5,7 @@
* Fix potential race condition when reopening the file (issue 5) * Fix potential race condition when reopening the file (issue 5)
* Fix potential blocking of `tail.Stop` (issue 4) * Fix potential blocking of `tail.Stop` (issue 4)
* Fix uncleaned up ChangeEvents goroutines after calling tail.Stop * Fix uncleaned up ChangeEvents goroutines after calling tail.Stop
* Support Follow=false
# Feb, 2013 # Feb, 2013

View File

@ -58,10 +58,6 @@ func TailFile(filename string, config Config) (*Tail, error) {
panic("cannot set ReOpen without Follow.") panic("cannot set ReOpen without Follow.")
} }
if !config.Follow {
panic("Follow=false is not supported.")
}
t := &Tail{ t := &Tail{
Filename: filename, Filename: filename,
Lines: make(chan *Line), Lines: make(chan *Line),
@ -160,6 +156,9 @@ func (tail *Tail) tailFileSync() {
tail.sendLine(line) tail.sendLine(line)
} }
case io.EOF: case io.EOF:
if !tail.Follow {
return
}
// When EOF is reached, wait for more data to become // When EOF is reached, wait for more data to become
// available. Wait strategy is based on the `tail.watcher` // available. Wait strategy is based on the `tail.watcher`
// implementation (inotify or polling). // implementation (inotify or polling).

View File

@ -66,6 +66,20 @@ func TestLocationFull(_t *testing.T) {
tail.Stop() tail.Stop()
} }
func TestLocationFullDontFollow(_t *testing.T) {
t := NewTailTest("location-full-dontfollow", _t)
t.CreateFile("test.txt", "hello\nworld\n")
tail := t.StartTail("test.txt", Config{Follow: false, Location: -1})
go t.VerifyTailOutput(tail, []string{"hello", "world"})
// Add more data only after reasonable delay.
<-time.After(100 * time.Millisecond)
t.AppendFile("test.txt", "more\ndata\n")
<-time.After(100 * time.Millisecond)
tail.Stop()
}
func TestLocationEnd(_t *testing.T) { func TestLocationEnd(_t *testing.T) {
t := NewTailTest("location-end", _t) t := NewTailTest("location-end", _t)
t.CreateFile("test.txt", "hello\nworld\n") t.CreateFile("test.txt", "hello\nworld\n")