Skip to content

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

Open

Description

@yayuntian

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

Activity

  1. chennqqi commented on Jul 2, 2017

    @chennqqi

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

  2. yayuntian commented on Jul 2, 2017

    @yayuntian
    Author

    hope fix Inotify

  3. yutengwan commented on Jul 3, 2017

    @yutengwan

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

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

  4. yayuntian commented on Jul 16, 2017

    @yayuntian
    Author

    @yutengwan 提交merge request呀

  5. anbaoyong commented on Aug 9, 2017

    @anbaoyong

    可以先用Poll的方式

  6. luzhzhsoft commented on Sep 19, 2018

    @luzhzhsoft

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions