diff --git a/lib/listen/adapter.rb b/lib/listen/adapter.rb index 058b8f50..7168cd54 100644 --- a/lib/listen/adapter.rb +++ b/lib/listen/adapter.rb @@ -4,10 +4,11 @@ require 'listen/adapter/linux' require 'listen/adapter/polling' require 'listen/adapter/windows' +require 'listen/adapter/simulated_darwin' module Listen module Adapter - OPTIMIZED_ADAPTERS = [Darwin, Linux, BSD, Windows] + OPTIMIZED_ADAPTERS = [Darwin, SimulatedDarwin, Linux, BSD, Windows] POLLING_FALLBACK_MESSAGE = 'Listen will be polling for changes.'\ 'Learn more at https://github.com/guard/listen#listen-adapters.' diff --git a/lib/listen/adapter/linux.rb b/lib/listen/adapter/linux.rb index 72f5e005..6801d732 100644 --- a/lib/listen/adapter/linux.rb +++ b/lib/listen/adapter/linux.rb @@ -50,11 +50,16 @@ def _process_event(dir, event) _log :debug, "inotify: #{rel_path} (#{event.flags.inspect})" if /1|true/ =~ ENV['LISTEN_GEM_SIMULATE_FSEVENT'] + @darwin ||= Class.new(Darwin) do + def _configure(dir, &callback) + end + end.new({mq: @mq}) + if (event.flags & [:moved_to, :moved_from]) || _dir_event?(event) rel_path = path.dirname.relative_path_from(dir).to_s - _queue_change(:dir, dir, rel_path, {}) + @darwin.send(:_process_event, dir, [(dir + rel_path).to_s + "/"]) else - _queue_change(:dir, dir, rel_path, {}) + @darwin.send(:_process_event, dir, [(dir + rel_path).to_s + "/"]) end return end diff --git a/lib/listen/adapter/simulated_darwin.rb b/lib/listen/adapter/simulated_darwin.rb new file mode 100644 index 00000000..60f0e7a2 --- /dev/null +++ b/lib/listen/adapter/simulated_darwin.rb @@ -0,0 +1,33 @@ +module Listen + module Adapter + class SimulatedDarwin < Linux + def self.usable? + os = RbConfig::CONFIG['target_os'] + return false unless const_get('OS_REGEXP') =~ os + /1|true/ =~ ENV['LISTEN_GEM_SIMULATE_FSEVENT'] + end + + def _process_event(dir, event) + # NOTE: avoid using event.absolute_name since new API + # will need to have a custom recursion implemented + # to properly match events to configured directories + path = Pathname.new(event.watcher.path) + event.name + rel_path = path.relative_path_from(dir).to_s + + _log :debug, "fake_fsevent: #{rel_path} (#{event.flags.inspect})" + + @darwin ||= Class.new(Darwin) do + def _configure(dir, &callback) + end + end.new({mq: @mq}) + + if (event.flags & [:moved_to, :moved_from]) || _dir_event?(event) + rel_path = path.dirname.relative_path_from(dir).to_s + @darwin.send(:_process_event, dir, [(dir + rel_path).to_s + "/"]) + else + @darwin.send(:_process_event, dir, [(dir + rel_path).to_s + "/"]) + end + end + end + end +end