hpcloud / tail

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

does not detect file that has been deleted and recreated #122

Open yayuntian opened 7 years ago

yayuntian commented 7 years ago

./gotail -F /root/messages Jun 22 14:42:43 node-247 SWARM: time="2017-06-22T14:42:44.507886233+08:00" level=debug msg="3"

when delete /root/messages and recreate it, gotail not detect file, sos

chennqqi commented 7 years ago

I test poll mode will trace delete and reopen ok. but Inotify does not

yayuntian commented 7 years ago

hope fix Inotify

yutengwan commented 7 years ago

我也遇到了这个问题,调试之后发现 在 hpcloud/tail/vendor/gopkg.in/fsnotify.v1/inotify.go文件中,rm文件操作 默认走到了

if mask&syscall.IN_ATTRIB == syscall.IN_ATTRIB {
        e.Op |= Chmod
 }

这个逻辑上 加上判断修改如下:

if mask&syscall.IN_ATTRIB == syscall.IN_ATTRIB {
        _, statErr := os.Lstat(e.Name)
        if os.IsNotExist(statErr) {
            e.Op |= Remove
        } else {
            e.Op |= Chmod
        }
 }

测试删除和然后新创建文件,然后新增内容可以获取到

yayuntian commented 7 years ago

@yutengwan 提交merge request呀

anbaoyong commented 7 years ago

可以先用Poll的方式

luzhzhsoft commented 5 years ago

@yayuntian @yutengwan 原因是这个。https://github.com/fsnotify/fsnotify/issues/194

试试修改下面fsnotify的代码。把忽略的消息放出来

// If the event is not a DELETE or RENAME, the file must exist.
// Otherwise the event is ignored.
// *Note*: this was put in place because it was seen that a MODIFY
// event was sent after the DELETE. This ignores that MODIFY and
// assumes a DELETE will come or has come if the file doesn't exist.
if !(e.Op&Remove == Remove || e.Op&Rename == Rename) {
    _, statErr := os.Lstat(e.Name)
    return os.IsNotExist(statErr)
}