Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yayuntian opened this issue Jun 22, 2017 · 6 comments
Open

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

yayuntian opened this issue Jun 22, 2017 · 6 comments

Comments

@yayuntian
Copy link

./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
Copy link

chennqqi commented Jul 2, 2017

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

@yayuntian
Copy link
Author

hope fix Inotify

@yutengwan
Copy link

我也遇到了这个问题,调试之后发现
在 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
Copy link
Author

@yutengwan 提交merge request呀

@anbaoyong
Copy link

可以先用Poll的方式

@luzhzhsoft
Copy link

luzhzhsoft commented Sep 19, 2018

@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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants