Skip to content

Instantly share code, notes, and snippets.

@ms-ati
Forked from e2/test_inotify.rb
Last active July 11, 2018 14:58
Show Gist options
  • Save ms-ati/b79e0998a27b64eb9e1354967f72021b to your computer and use it in GitHub Desktop.
Save ms-ati/b79e0998a27b64eb9e1354967f72021b to your computer and use it in GitHub Desktop.
Script for testing inotify and listen on Linux
gem "rb-inotify"
require 'rb-inotify'
gem "listen"
require "listen"
# BEGIN MONKEY PATCH OF LISTEN GEM
Listen::Adapter::Linux::DEFAULTS.tap do |defaults|
# Add :modify to the inotify events monitored by the Linux adapter
new_defaults = defaults.merge(events: defaults[:events] + [:modify])
Listen::Adapter::Linux.const_set(:DEFAULTS, new_defaults.freeze)
end
# END MONKEY PATCH OF LISTEN GEM
dir = '.'
Listen.to(dir) do |modified, added, removed|
puts "listen: #{[added, modified, removed].inspect}!"
end.start
events = [:recursive, :attrib, :create, :delete, :move, :close_write]
# Add :modify to the inotify events -- this is what we were missing!
events += [:modify]
INotify::Notifier.new.tap do |notifier|
notifier.watch(dir, *events) do |event|
puts "rb-inotify event: #{event.name} #{event.flags.inspect}"
end
notifier.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment