-
-
Save ms-ati/b79e0998a27b64eb9e1354967f72021b to your computer and use it in GitHub Desktop.
Script for testing inotify and listen on Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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