Closed petur03 closed 4 years ago
I can't reproduce this. The handler never gets unregistered for me.
I was experiencing the same problem. Used @petur03 implementation and it works like I expected. I should probably mention that am running it against ruby-2.0.0-p0 on an Ubuntu 11.10 box.
I had the same problem. For me, it was because I was editing my file with Vim. If I echoed text to the file, it worked fine.
I found the solution to my problem in this Super User answer: http://superuser.com/a/181543
I implemented his solution as such:
require 'rb-inotify'
notifier = INotify::Notifier.new
notifier.watch('.', :close_write, :moved_to, :create) do |event|
puts 'dummy.txt was updated' if event.name == 'dummy.txt'
end
notifier.run
This detects the change whether the file is written to directly or replaced with another file.
Yeah I think this is expected, it's monitoring specific inode, and editors regularly delete file and write new one, so you'll just get delete event and that's it, inode you're watching is gone. Maybe high-level API should have option to follow file name, essentially implement solution like eclubb's when given argument like :follow?
I like the idea of hiding behind a :follow
arg.
I'm fine with having a flag for this, but I'm not a fan of the name :follow
; it sounds like it's referring to symlinks somehow. I'd prefer something like :resubscribe
.
No contest on name, fine with any. Another method is also option, perhaps #watch_name, would avoid overloading configuration arguments with event types and have more obvious fail with older versions of API ran against code using it.
We already overload configuration arguments for :recursive
, but you make a good point about providing an obvious error. We should really be throwing an error for unrecognized flags anyway.
I think I slightly prefer a flag, since that allows flags to compose more seamlessly.
Completely okey with flag, just spitballing.
I also see this failure to re-register events, under Ubuntu 14.04
with jRuby 1.7.12
The solution is to handle the flag ":ignored" and re-instance the notifier.watch whenever you receive one.
Now that we have test, it would be great to add a spec for this including some documentation for the correct way this should be handled.
Feel free to submit a failing PR either here or in the listen gem.
Hi
I've been using your gem, but it's not working quite as I would expect.
It seems that I have to reregister the watcher whenever an event has occurred. So running notifier.run will loop forever, but only handle each registered event once. To continuously handle events I have to use notifier.process in a loop and run notifier.watch after process, see example below. If I omit the call to watch() in the loop, the handler will only be called the first time the file is modified.
I don't know if this is intended behaviour or not, at least I don't think it is reflected in the readme.
Thanks, Petur