guard / rb-inotify

A thorough inotify wrapper for Ruby using FFI.
MIT License
312 stars 64 forks source link

Strange behavior of :delete_self #83

Closed fsobanski closed 6 years ago

fsobanski commented 6 years ago

Hi,

when I create the script asdf.rb with the following content

require 'rb-inotify'

notifier = INotify::Notifier.new
notifier.watch('foo.txt', :delete_self) {puts "foo.txt was deleted!"}
File.delete 'foo.txt'
notifier.process

and then execute the following commands under Debian:

touch foo.txt
ruby asdf.rb

I get the output:

foo.txt was deleted!
foo.txt was deleted!

So the event fired twice. Do you know why?

When I execute the following script instead:

require 'rb-inotify'

notifier = INotify::Notifier.new
File.new 'foo.txt', 'w'
notifier.watch('foo.txt', :delete_self) {puts "foo.txt was deleted!"}
File.delete 'foo.txt'
notifier.process

then I get no output at all. So the event never fired...

fsobanski commented 6 years ago

Alright, when I change the lower example code to the following, then the events are fired again.

require 'rb-inotify'

notifier = INotify::Notifier.new
f = File.new 'foo.txt', 'w'
f.close
notifier.watch('foo.txt', :delete_self) {puts "foo.txt was deleted!"}
File.delete 'foo.txt'
notifier.process

And when I change :delete_self to :delete, only one event is emitted as expected.