does not detect file that has been deleted and recreated
yayuntian opened this issue · 6 comments
yayuntian commented
./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
I test poll mode will trace delete and reopen ok. but Inotify does not
yayuntian commented
hope fix Inotify
yutengwan commented
我也遇到了这个问题,调试之后发现
在 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
@yutengwan 提交merge request呀
anbaoyong commented
可以先用Poll的方式
luzhzhsoft commented
@yayuntian @yutengwan 原因是这个。fsnotify/fsnotify#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)
}