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

run_on_modifications no longer firing for Kate on Linux. #180

Closed
jonmast opened this issue Jan 15, 2014 · 34 comments
Closed

run_on_modifications no longer firing for Kate on Linux. #180

jonmast opened this issue Jan 15, 2014 · 34 comments

Comments

@jonmast
Copy link

jonmast commented Jan 15, 2014

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

total  attrib  delete_self  filename
3      1       1            catalogdetail.tpl

run_on_changes fires fine.

@thibaudgg
Copy link
Member

That's weird because attrib event is listened: https://github.com/guard/listen/blob/master/lib/listen/adapter/linux.rb#L12

Could you try to play/debug a little bit that class with your setup? Thanks!

@jonmast
Copy link
Author

jonmast commented Feb 2, 2014

I played around with it a bit and it seems like its never getting the event. The only event for the file in _worker_callback is moved_to

@thibaudgg
Copy link
Member

Ok that's weird, moved_to is called when file is moved into the watched directory (https://github.com/nex3/rb-inotify/blob/master/lib/rb-inotify/notifier.rb#L126), so we can't match that for run_on_modifications. Maybe try to contact directly Kate authors to see if it possible to fix that on their side.

@thibaudgg
Copy link
Member

Still an issue?

@e2
Copy link
Contributor

e2 commented Apr 17, 2014

Yes, it's still an issue. And it's not trivial...

Kate likely does the same thing Sublime Text 3 does on Linux, which is:

  1. reading the catalogdetail.tpl contents
  2. creating a tmp file
  3. writing what it just read to the tmp file
  4. deleting catalogdetail.tpl
  5. moving the tmp file to catalogdetail.tpl

It seems like this would trigger the sequence:

  1. attrib => :modified
  2. :deleted_self => :deleted
  3. :moved_to => :created

which is more than sufficient for listen to realize it's really a :modified change.

But what's happening is there's an :added change instead (which is why run_on_changes is called and why nothing happens).

Because both the :attrib and :delete_self happen on the file, not the directory.

That's because the :delete_self is result of a rename() call by Sublime/Kate, so no actual deleting even takes place (see man 1 rename for details why).

That's why the :attrib appears in inotifywatch (if the file is given on the command line while it exists), but not in the listen adapter (which doesn't listen for specific files, but the directory).

And Listen can't catch the :attrib or :delete_self if it sets up rb-inotify to watch a directory - and not the file.

That's why only :moved_to is left - which is the only inotify event happening on the directory in this scenario. Since this is a :moved_to event, it's translated as :added, so it doesn't trigger run_on_modifications.

@thibaudgg
Copy link
Member

What about simplify the whole api and merging added/removed/modified to a simple and unique modified event and leave Listen users to handle it the way they want... Like you propose before right?

@e2
Copy link
Contributor

e2 commented Apr 17, 2014

Yes - though this technically means forking listen into listen2 and guard into guard2, so I've created these:

@thibaudgg
Copy link
Member

👍

@e2
Copy link
Contributor

e2 commented Apr 18, 2014

This issue should be fixed in: #215

@e2
Copy link
Contributor

e2 commented May 2, 2014

Kate is still broken (see: #217 or guard/guard-rspec#262)

gem 'listen', github: 'guard/listen', branch: 'kate_editing_tmp_ignores'

(Bundle install, restart guard, etc.)

This branch should fix things for Kate: https://github.com/guard/listen/tree/kate_editing_tmp_ignores

... because the new ignore patterns would allow the patch from #215 to kick in.

@dima4p
Copy link

dima4p commented May 2, 2014

Yes, branch kate_editing_tmp_ignores works for me at least

@dima4p
Copy link

dima4p commented May 2, 2014

My consideration: is not it easier to analyze listen: final changes event?

@e2
Copy link
Contributor

e2 commented May 2, 2014

listen: final changes is just a debug text showing how the inotify events (raw changes) were "reinterpreted" to detect the adding + moving/renaming as a "modify" for Kate and Sublime editors.

listen: inotify event - those debugs show what rb-inotify reports.

In the upcoming version of listen (in progress), there won't be any added/removed events, just "modify" so most of the code will be thrown away anyway.

@e2
Copy link
Contributor

e2 commented May 2, 2014

@thibaudgg - I drafted a release: https://github.com/guard/listen/releases

It's worth releasing, because Kate users will have an exceptionally tough time debugging why their editor doesn't work.

Could you check/release v2.7.4 ? Thanks!

@thibaudgg
Copy link
Member

Done, thanks for the draft (and the fix)!

@e2
Copy link
Contributor

e2 commented May 2, 2014

👍 Awesome, thanks!

@e2 e2 closed this as completed May 2, 2014
@dima4p
Copy link

dima4p commented May 4, 2014

Great, thank you. :-)

@e2
Copy link
Contributor

e2 commented May 4, 2014

My pleasure :)

@dima4p
Copy link

dima4p commented May 4, 2014

After some experience I'v'e met a problem. Sometimes it is needed to save the file several times before the guard is triggered. Shall I open a new issue?

@dima4p
Copy link

dima4p commented May 4, 2014

Here is the output when guard is not triggered:
[1] guard(main)> I, [2014-05-04T22:12:07.102816 #2801] INFO -- : listen: inotify event: [:create]: qt_temp.c22583
I, [2014-05-04T22:12:07.103411 #2801] INFO -- : listen: inotify event: [:close_write, :close]: qt_temp.c22583
I, [2014-05-04T22:12:07.103540 #2801] INFO -- : listen: inotify event: [:moved_from, :move]: qt_temp.c22583
I, [2014-05-04T22:12:07.103696 #2801] INFO -- : listen: inotify event: [:moved_to, :move]: show.html.haml~
I, [2014-05-04T22:12:07.103784 #2801] INFO -- : listen: inotify event: [:attrib]: show.html.haml~
I, [2014-05-04T22:12:07.124986 #2801] INFO -- : listen: inotify event: [:create]: show.html.hamlJ22583.new
I, [2014-05-04T22:12:07.125261 #2801] INFO -- : listen: inotify event: [:attrib]: show.html.hamlJ22583.new
I, [2014-05-04T22:12:07.125380 #2801] INFO -- : listen: inotify event: [:close_write, :close]: show.html.hamlJ22583.new
I, [2014-05-04T22:12:07.196262 #2801] INFO -- : listen: inotify event: [:close_write, :close]: show.html.hamlJ22583.new
I, [2014-05-04T22:12:07.196812 #2801] INFO -- : listen: inotify event: [:moved_from, :move]: show.html.hamlJ22583.new
I, [2014-05-04T22:12:07.196943 #2801] INFO -- : listen: inotify event: [:moved_to, :move]: show.html.haml
I, [2014-05-04T22:12:07.197035 #2801] INFO -- : listen: inotify event: [:close_write, :close]: .show.html.haml.kate-swp
I, [2014-05-04T22:12:07.197150 #2801] INFO -- : listen: inotify event: [:delete]: .show.html.haml.kate-swp
I, [2014-05-04T22:12:07.312700 #2801] INFO -- : listen: raw changes: [[nil, "/home/dima/devel/www/project/app/views/cookies/qt_temp.c22583"], [nil, "/home/dima/devel/www/project/app/views/cookies/show.html.hamlJ22583.new"], [:removed, "/home/dima/devel/www/project/app/views/cookies/.show.html.haml.kate-swp"], [:added, "/home/dima/devel/www/project/app/views/cookies/show.html.haml"]]
I, [2014-05-04T22:12:07.312791 #2801] INFO -- : listen: final changes: {:modified=>[], :added=>["/home/dima/devel/www/project/app/views/cookies/show.html.haml"], :removed=>["/home/dima/devel/www/project/app/views/cookies/.show.html.haml.kate-swp"]}

@dima4p
Copy link

dima4p commented May 4, 2014

Two in the sequence:
[1] guard(main)> I, [2014-05-04T22:16:28.580485 #2801] INFO -- : listen: inotify event: [:create]: qt_temp.C22583
I, [2014-05-04T22:16:28.581304 #2801] INFO -- : listen: inotify event: [:close_write, :close]: qt_temp.C22583
I, [2014-05-04T22:16:28.581453 #2801] INFO -- : listen: inotify event: [:moved_from, :move]: qt_temp.C22583
I, [2014-05-04T22:16:28.581564 #2801] INFO -- : listen: inotify event: [:moved_to, :move]: show.html.haml_spec.rb~
I, [2014-05-04T22:16:28.582476 #2801] INFO -- : listen: inotify event: [:attrib]: show.html.haml_spec.rb~
I, [2014-05-04T22:16:28.600430 #2801] INFO -- : listen: inotify event: [:create]: show.html.haml_spec.rbX22583.new
I, [2014-05-04T22:16:28.600879 #2801] INFO -- : listen: inotify event: [:attrib]: show.html.haml_spec.rbX22583.new
I, [2014-05-04T22:16:28.600997 #2801] INFO -- : listen: inotify event: [:close_write, :close]: show.html.haml_spec.rbX22583.new
I, [2014-05-04T22:16:28.667031 #2801] INFO -- : listen: inotify event: [:close_write, :close]: show.html.haml_spec.rbX22583.new
I, [2014-05-04T22:16:28.667465 #2801] INFO -- : listen: inotify event: [:moved_from, :move]: show.html.haml_spec.rbX22583.new
I, [2014-05-04T22:16:28.667707 #2801] INFO -- : listen: inotify event: [:moved_to, :move]: show.html.haml_spec.rb
I, [2014-05-04T22:16:28.667823 #2801] INFO -- : listen: inotify event: [:close_write, :close]: .show.html.haml_spec.rb.kate-swp
I, [2014-05-04T22:16:28.667921 #2801] INFO -- : listen: inotify event: [:delete]: .show.html.haml_spec.rb.kate-swp
I, [2014-05-04T22:16:28.833639 #2801] INFO -- : listen: raw changes: [[nil, "/home/dima/devel/www/project/spec/views/cookies/qt_temp.C22583"], [nil, "/home/dima/devel/www/project/spec/views/cookies/show.html.haml_spec.rbX22583.new"], [:removed, "/home/dima/devel/www/project/spec/views/cookies/.show.html.haml_spec.rb.kate-swp"], [:added, "/home/dima/devel/www/project/spec/views/cookies/show.html.haml_spec.rb"]]
I, [2014-05-04T22:16:28.833731 #2801] INFO -- : listen: final changes: {:modified=>[], :added=>["/home/dima/devel/www/project/spec/views/cookies/show.html.haml_spec.rb"], :removed=>["/home/dima/devel/www/project/spec/views/cookies/.show.html.haml_spec.rb.kate-swp"]}
[1] guard(main)> I, [2014-05-04T22:16:33.895184 #2801] INFO -- : listen: inotify event: [:delete]: show.html.haml_spec.rb~
I, [2014-05-04T22:16:33.896048 #2801] INFO -- : listen: inotify event: [:create]: qt_temp.l22583
I, [2014-05-04T22:16:33.896191 #2801] INFO -- : listen: inotify event: [:close_write, :close]: qt_temp.l22583
I, [2014-05-04T22:16:33.896283 #2801] INFO -- : listen: inotify event: [:moved_from, :move]: qt_temp.l22583
I, [2014-05-04T22:16:33.896416 #2801] INFO -- : listen: inotify event: [:moved_to, :move]: show.html.haml_spec.rb~
I, [2014-05-04T22:16:33.896503 #2801] INFO -- : listen: inotify event: [:attrib]: show.html.haml_spec.rb~
I, [2014-05-04T22:16:33.913039 #2801] INFO -- : listen: inotify event: [:create]: show.html.haml_spec.rbB22583.new
I, [2014-05-04T22:16:33.913633 #2801] INFO -- : listen: inotify event: [:attrib]: show.html.haml_spec.rbB22583.new
I, [2014-05-04T22:16:33.913826 #2801] INFO -- : listen: inotify event: [:close_write, :close]: show.html.haml_spec.rbB22583.new
I, [2014-05-04T22:16:33.964940 #2801] INFO -- : listen: inotify event: [:close_write, :close]: show.html.haml_spec.rbB22583.new
I, [2014-05-04T22:16:33.965444 #2801] INFO -- : listen: inotify event: [:moved_from, :move]: show.html.haml_spec.rbB22583.new
I, [2014-05-04T22:16:33.965561 #2801] INFO -- : listen: inotify event: [:moved_to, :move]: show.html.haml_spec.rb
I, [2014-05-04T22:16:34.144845 #2801] INFO -- : listen: raw changes: [[nil, "/home/dima/devel/www/project/spec/views/cookies/qt_temp.l22583"], [nil, "/home/dima/devel/www/project/spec/views/cookies/show.html.haml_spec.rbB22583.new"], [:added, "/home/dima/devel/www/project/spec/views/cookies/show.html.haml_spec.rb"]]
I, [2014-05-04T22:16:34.144932 #2801] INFO -- : listen: final changes: {:modified=>[], :added=>["/home/dima/devel/www/project/spec/views/cookies/show.html.haml_spec.rb"], :removed=>[]}

@e2
Copy link
Contributor

e2 commented May 4, 2014

Nah, same issue.

@e2
Copy link
Contributor

e2 commented May 4, 2014

My bad - I screwed up the regexp for Kate. I think it should work now, no matter what process id or random string is generated by Kate for temp file.

Could you switch to the master branch and test to make sure it's triggered every time? (I should have installed Kate myself to test, but I couldn't get myself to download KDE before the Ubuntu upgrade).

@e2 e2 reopened this May 4, 2014
@e2
Copy link
Contributor

e2 commented May 4, 2014

One question - do you have any idea where the .kate-swp files come from? A Kate plugin or something? Because as far as I've seen, Kate creates backup files according to configured prefix+suffix (default is ending files with '~' AFAIK) and creating temp files with the XXXXXX.new mask (e.g. X's = char + 5 x digits from process PID).

@dima4p
Copy link

dima4p commented May 4, 2014

yes, kate swap keeps the changes until they are saved to the file

@dima4p
Copy link

dima4p commented May 4, 2014

With master I could not repeat the issue: every save triggers guard.

@dima4p
Copy link

dima4p commented May 4, 2014

kate-swp is created at the making any change in the file and is deleted after the file is saved:
[1] guard(main)> I, [2014-05-04T23:49:18.941034 #24945] INFO -- : listen: inotify event: [:create]: .main_controller_spec.rb.kate-swp
I, [2014-05-04T23:49:19.119190 #24945] INFO -- : listen: raw changes: [[:added, "/home/dima/devel/www/project/spec/controllers/.main_controller_spec.rb.kate-swp"]]
I, [2014-05-04T23:49:19.119283 #24945] INFO -- : listen: final changes: {:modified=>[], :added=>["/home/dima/devel/www/project/spec/controllers/.main_controller_spec.rb.kate-swp"], :removed=>[]}
[1] guard(main)> I, [2014-05-04T23:49:22.686396 #24945] INFO -- : listen: inotify event: [:delete]: main_controller_spec.rb~
I, [2014-05-04T23:49:22.687385 #24945] INFO -- : listen: inotify event: [:create]: qt_temp.G22583
I, [2014-05-04T23:49:22.687531 #24945] INFO -- : listen: inotify event: [:close_write, :close]: qt_temp.G22583
I, [2014-05-04T23:49:22.687636 #24945] INFO -- : listen: inotify event: [:moved_from, :move]: qt_temp.G22583
I, [2014-05-04T23:49:22.687730 #24945] INFO -- : listen: inotify event: [:moved_to, :move]: main_controller_spec.rb~
I, [2014-05-04T23:49:22.687827 #24945] INFO -- : listen: inotify event: [:attrib]: main_controller_spec.rb~
I, [2014-05-04T23:49:22.706688 #24945] INFO -- : listen: inotify event: [:create]: main_controller_spec.rbG22583.new
I, [2014-05-04T23:49:22.706899 #24945] INFO -- : listen: inotify event: [:attrib]: main_controller_spec.rbG22583.new
I, [2014-05-04T23:49:22.706993 #24945] INFO -- : listen: inotify event: [:close_write, :close]: main_controller_spec.rbG22583.new
I, [2014-05-04T23:49:22.760135 #24945] INFO -- : listen: inotify event: [:close_write, :close]: main_controller_spec.rbG22583.new
I, [2014-05-04T23:49:22.760717 #24945] INFO -- : listen: inotify event: [:moved_from, :move]: main_controller_spec.rbG22583.new
I, [2014-05-04T23:49:22.760865 #24945] INFO -- : listen: inotify event: [:moved_to, :move]: main_controller_spec.rb
I, [2014-05-04T23:49:22.760962 #24945] INFO -- : listen: inotify event: [:close_write, :close]: .main_controller_spec.rb.kate-swp
I, [2014-05-04T23:49:22.761054 #24945] INFO -- : listen: inotify event: [:delete]: .main_controller_spec.rb.kate-swp
I, [2014-05-04T23:49:22.935620 #24945] INFO -- : listen: raw changes: [[nil, "/home/dima/devel/www/project/spec/controllers/qt_temp.G22583"], [:removed, "/home/dima/devel/www/project/spec/controllers/.main_controller_spec.rb.kate-swp"], [:modified, "/home/dima/devel/www/project/spec/controllers/main_controller_spec.rb"]]
I, [2014-05-04T23:49:22.935717 #24945] INFO -- : listen: final changes: {:modified=>["/home/dima/devel/www/project/spec/controllers/main_controller_spec.rb"], :added=>[], :removed=>["/home/dima/devel/www/project/spec/controllers/.main_controller_spec.rb.kate-swp"]}
23:49:22 - INFO - Running: ./spec/controllers/main_controller_spec.rb:14 ./spec/controllers/main_controller_spec.rb:19
Run options: include {:locations=>{"./spec/controllers/main_controller_spec.rb"=>[14, 19]}}

@e2
Copy link
Contributor

e2 commented May 5, 2014

Now on master kate-swp files are ignored, so this should avoid useless guard triggering.

@dima4p
Copy link

dima4p commented May 5, 2014

Btw, I did not experience false triggering of guard from kate.

@e2
Copy link
Contributor

e2 commented May 5, 2014

Btw, I did not experience false triggering of guard from Kate.

Thanks for letting me know - I appreciate that.

@e2
Copy link
Contributor

e2 commented May 14, 2014

@thibaudgg - I think we can close this and a few other issues already fixed on master. I've prepared a draft for v2.7.5, could you release it if you find a moment?

@thibaudgg
Copy link
Member

2.7.5 released, thanks!

@dima4p
Copy link

dima4p commented May 15, 2014

Thank you

@e2
Copy link
Contributor

e2 commented May 15, 2014

Our pleasure :)

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

No branches or pull requests

5 participants