Skip to content

Duplicate events for delete folder due to unix.IN_DELETE_SELF #299

@Kimbsen

Description

@Kimbsen
uname -a
Linux kimsubuntu 4.4.0-150-generic #176-Ubuntu SMP Wed May 29 18:56:26 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

When deleting a watched directory several inotify events are emitted.

For example using inotifywait to display ALL events:

$ inotifywait -m -r root/
Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.

# mkdir root/test
    root/ CREATE,ISDIR                test
    root/ OPEN,ISDIR                  test
    root/ ACCESS,ISDIR                test
    root/ CLOSE_NOWRITE,CLOSE,ISDIR   test

# rm -rf root/test
    root/        OPEN,ISDIR                   test
    root/test/   OPEN,ISDIR
    root/        ACCESS,ISDIR                 test
    root/test/   ACCESS,ISDIR
    root/        ACCESS,ISDIR                 test
    root/test/   ACCESS,ISDIR
    root/        CLOSE_NOWRITE,CLOSE,ISDIR    test
    root/test/   CLOSE_NOWRITE,CLOSE,ISDIR
    root/test/   DELETE_SELF
    root/        DELETE,ISDIR                 test

fsnotify doesn't receive/care about all of these due to the flags passed to unix.InotifyAddWatch but both the DELETE_SELF and DELETE events are converted to fsnotify.REMOVE events and both are emitted on watcher.Events.

Example using fsnotify in a test application:

$ ./testapp root
12:25:37.139029 started with root /home/kim/inotifytest/root

# mkdir root/test
    12:25:41.834888 E => "/home/kim/inotifytest/root/test": CREATE

# rm -rf root/test
    12:25:45.211957 E => "/home/kim/inotifytest/root/test": REMOVE
    12:25:45.212139 E => "/home/kim/inotifytest/root/test": REMOVE

I'm not sure if there is any case where only one of them will be emitted by the underlying inotify, but i think the DELETE event will be there in every case of flags passed to unix.InotifyAddWatch in fsnotify.

What I'm proposing is to not emit a REMOVE event for the underlying IN_DELETE_SELF event, possibly by adding it to the func (e *Event) ignoreLinux(mask uint32) bool function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions