hpcloud / tail

Go package for reading from continously updated files (tail -f)
MIT License
2.72k stars 505 forks source link

Fixes file truncation on Mac. #113

Closed vladlosev closed 7 years ago

vladlosev commented 7 years ago

This change fixes file truncation on Mac OS X (I have 10.11.6). The current code is broken there:

Vlads-MacBook-Air:tail vlad$ go test --test.run=TestReSeekInotify
2017/03/17 19:16:14 Stopping tail as file no longer exists: .test/reseek-inotify/test.txt
--- FAIL: TestReSeekInotify (0.20s)
    tail_test.go:499: tail ended early; expecting more: [h311o w0r1d endofworld]
FAIL
exit status 1
FAIL    github.com/hpcloud/tail 0.213s

The problems is that the file truncation operation apparently sends the Chmod event in Mac OS X, and the ChangeEvents function's Chmod case allows that event to fall through into the Rename case which removes the watch, preventing further updates.

This change discriminates between the case of non-existent file, which still falls through, and existing file, which causes the function to continue listening.

vladlosev commented 7 years ago

It looks like #111 is a better approach to this fix WRT error handling - closing in favor of it.