Skip to content

Multiple calls per watch event on linux with rb-inotify #98

Closed

Description

@jeffutter

It seems that in some cases rb-inotify is generating multiple events when it should only be generating one.

My specific scenario:

I'm using the sublimetext editor. When saving a file with sublimetext it uses one fwrite operation and then multiple writes in 4k blocks.

as can be seen here:
https://github.com/guard/guard/blob/master/lib/guard/listeners/linux.rb#L50

Guard is watching for :close_write and :modify events. A modify event gets triggered for every 4k block written by the editor. If guard just listened for :close_write it would only trigger once when the editor has closed the file handle. I can't really think of any situation where :modify would be needed, but there may be some.

Activity

  1. netzpirat commented on Jun 29, 2011

    @netzpirat

    From the inotifywatch man page:

    modify
        A watched file or a file within a watched directory was written to.
    
    close_write
        A watched file or a file within a watched directory was closed, after being opened
        in writeable mode. This does not necessarily imply the file was written to.
    

    So when the editor writes a file in chunks, it fires several :modify and a single :close_write. So from my understanding, when removing :modify from the listener, we'll catch only the end of the write operation. However there may be other editors that keeps a file handle open and thus fires only :modify events.

    I'm not sure how to approach this, since it may break another editor and I'm not using Linux on my development machine. I'd like to see more analysis of inotify events for other popular editors like vim, nano, joe, gedit, kate, SciTE, etc.

  2. jeffutter commented on Jun 29, 2011

    @jeffutter
    Author

    Here is the inotifywatch output from a few common editors. I opened the file, launched inotifywatch, changed it, saved it, killed inotify watch:

    Sublime Text

    total  modify  close_write  open  filename
    5      3       1            1     coffee/script.coffee
    

    Vim

    total  attrib  move_self  delete_self  filename
    4      1       1          1            coffee/script.coffee
    

    Gedit

    total  access  attrib  close_write  close_nowrite  open  delete_self  filename
    8      1       1       1            1              2     1            coffee/script.coffee
    

    nano

    total  modify  close_write  open  filename
    5      3       1            1     coffee/script.coffee
    

    joe

    total  access  modify  attrib  close_write  close_nowrite  open  filename
    10     1       4       1       1            1              2     coffee/script.coffee
    

    jedit

    total  move_self  filename
    1      1          coffee/script.coffee
    

    scite

    total  modify  close_write  open  filename
    5      3       1            1     coffee/script.coffee
    

    bluefish

    total  attrib  close_write  open  filename
    4      2       1            1     coffee/script.coffee
    

    echo 'foo' > coffee/test.txt

    total  modify  close_write  open  filename
    4      2       1            1     coffee/test.txt
    

    It looks to me like everything has a close_write except for a few that have neither close_write nor modify. I think these ones write to a tmp file and then move it into place over the existing file.

  3. netzpirat commented on Jun 29, 2011

    @netzpirat

    Awesome job! I will take care of it tomorrow. Thanks a lot.

  4. thibaudgg commented on Jun 29, 2011

    @thibaudgg
    Member

    Seems like supporting only close_write & move_self (for vim & jedit) would cover 100% of editors listed above. Thanks these info, that's really helpful!

  5. schadenfred commented on Jun 29, 2011

    @schadenfred

    I'd like to add this issue, which is now closed, to this thread:

    guard/guard-rspec#26 (comment)

  6. thibaudgg commented on Jul 2, 2011

    @thibaudgg
    Member

    Fixed in this commit

  7. jonmast commented on Jan 12, 2014

    @jonmast

    With Kate 3.12 run_on_modifications is no longer being fired. Output from inotifywatch is:

    total  attrib  delete_self  filename
    3      1       1            catalogdetail.tpl
    
  8. rymai commented on Jan 14, 2014

    @rymai
    Member

    @onlineamateur Please report any listener issue directly in the Listen issue tracker since it's handled there now. Thanks!

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