listen 2.7.5 → 2.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/.rubocop.yml +0 -0
  5. data/.travis.yml +0 -1
  6. data/.yardopts +0 -0
  7. data/CHANGELOG.md +0 -0
  8. data/CONTRIBUTING.md +0 -0
  9. data/Gemfile +25 -4
  10. data/Guardfile +0 -0
  11. data/LICENSE.txt +0 -0
  12. data/README.md +18 -10
  13. data/Rakefile +0 -0
  14. data/lib/listen.rb +2 -4
  15. data/lib/listen/adapter.rb +13 -4
  16. data/lib/listen/adapter/base.rb +33 -16
  17. data/lib/listen/adapter/bsd.rb +21 -38
  18. data/lib/listen/adapter/darwin.rb +17 -25
  19. data/lib/listen/adapter/linux.rb +34 -52
  20. data/lib/listen/adapter/polling.rb +9 -25
  21. data/lib/listen/adapter/tcp.rb +27 -14
  22. data/lib/listen/adapter/windows.rb +67 -23
  23. data/lib/listen/change.rb +26 -23
  24. data/lib/listen/cli.rb +0 -0
  25. data/lib/listen/directory.rb +47 -58
  26. data/lib/listen/file.rb +66 -101
  27. data/lib/listen/listener.rb +214 -155
  28. data/lib/listen/queue_optimizer.rb +104 -0
  29. data/lib/listen/record.rb +15 -5
  30. data/lib/listen/silencer.rb +14 -10
  31. data/lib/listen/tcp.rb +0 -1
  32. data/lib/listen/tcp/broadcaster.rb +31 -26
  33. data/lib/listen/tcp/message.rb +2 -2
  34. data/lib/listen/version.rb +1 -1
  35. data/listen.gemspec +1 -1
  36. data/spec/acceptance/listen_spec.rb +151 -239
  37. data/spec/acceptance/tcp_spec.rb +125 -134
  38. data/spec/lib/listen/adapter/base_spec.rb +13 -30
  39. data/spec/lib/listen/adapter/bsd_spec.rb +7 -35
  40. data/spec/lib/listen/adapter/darwin_spec.rb +18 -30
  41. data/spec/lib/listen/adapter/linux_spec.rb +49 -55
  42. data/spec/lib/listen/adapter/polling_spec.rb +20 -35
  43. data/spec/lib/listen/adapter/tcp_spec.rb +25 -27
  44. data/spec/lib/listen/adapter/windows_spec.rb +7 -33
  45. data/spec/lib/listen/adapter_spec.rb +10 -10
  46. data/spec/lib/listen/change_spec.rb +55 -57
  47. data/spec/lib/listen/directory_spec.rb +105 -155
  48. data/spec/lib/listen/file_spec.rb +186 -73
  49. data/spec/lib/listen/listener_spec.rb +233 -216
  50. data/spec/lib/listen/record_spec.rb +60 -22
  51. data/spec/lib/listen/silencer_spec.rb +48 -75
  52. data/spec/lib/listen/tcp/broadcaster_spec.rb +78 -69
  53. data/spec/lib/listen/tcp/listener_spec.rb +28 -71
  54. data/spec/lib/listen/tcp/message_spec.rb +48 -14
  55. data/spec/lib/listen_spec.rb +3 -3
  56. data/spec/spec_helper.rb +6 -3
  57. data/spec/support/acceptance_helper.rb +250 -31
  58. data/spec/support/fixtures_helper.rb +6 -4
  59. data/spec/support/platform_helper.rb +2 -2
  60. metadata +5 -5
  61. data/lib/listen/tcp/listener.rb +0 -108
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2b1fec6652b9c788556648b883430623b4953d2
4
- data.tar.gz: 84e2262d6b7952b3afdb08defa5035604718f2f9
3
+ metadata.gz: 962fc43324f716a5abe1d8acd8ea5df7c87d3d28
4
+ data.tar.gz: 84b801baff1f5026d64b15df0c9de5fceac572b7
5
5
  SHA512:
6
- metadata.gz: 3b7d31da3edbb75296f7bc8f174c192c9317f87295c13eca6081fbac78793b8b28a9d88851e00f9b74dce5cff508d6bf31ab5e552e1fb1f941160589809a8aba
7
- data.tar.gz: 6d4df130ce978ecbbb46069030d1a7324aac5624719c2129d570e6fb7b5553035e4c44dd3c5a9618ec07d2bae9bc6a0099b44dbe448c4b90355ac08620d9ddcd
6
+ metadata.gz: d95876a7d2bd3a39a8130685e2dfa40745ee6ca947646aa303a42b0ab1c4d8bb92347adf2b7e817209840c0a973a813ee5b3d90aafe0db6541361f2fa0d6b5a3
7
+ data.tar.gz: 3cf94f221c2c4debd84f14a4545ba6caecb45bf6c1d3097ab5482d4ce9e907858aa80d736cc66d54d74e9e100423aca970515ccc0debf89dfb5990f16d169752
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
File without changes
@@ -13,7 +13,6 @@ matrix:
13
13
  notifications:
14
14
  recipients:
15
15
  - thibaud@thibaud.gg
16
- - remy@rymai.me
17
16
  os:
18
17
  - linux
19
18
  - osx
data/.yardopts CHANGED
File without changes
File without changes
File without changes
data/Gemfile CHANGED
@@ -3,14 +3,35 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  require 'rbconfig'
6
- gem 'wdm', '>= 0.1.0' if RbConfig::CONFIG['target_os'] =~ /mswin|mingw|cygwin/i
7
6
 
8
- if RbConfig::CONFIG['target_os'] =~ /bsd|dragonfly/i
7
+ case RbConfig::CONFIG['target_os']
8
+
9
+ when /mswin|mingw|cygwin/i
10
+ gem 'wdm', '>= 0.1.0'
11
+ Kernel.warn 'NOTE: Known issues for your platform:'
12
+ Kernel.warn ' * celluloid-io dns resovler bug causes TCP adapter to fail'
13
+ Kernel.warn ' (fixed celluloid-io requires unreleased celluloid version)'
14
+ Kernel.warn " * celluloid master branch doesn't work properly on Windows"
15
+
16
+ # has fix, but causes above other problems:
17
+ # gem 'celluloid-io', github: 'celluloid/celluloid-io', ref: 'a72cae2e'
18
+
19
+ when /bsd|dragonfly/i
20
+
9
21
  gem 'rb-kqueue', '>= 0.2'
10
- # Versions not included have known bugs
11
- # Even master branches may not work...
22
+
23
+ Kernel.warn 'NOTE: BSD is unsupported because:'
24
+ Kernel.warn "* Ruby threads don't work correctly (Ruby/MRI unit tests)"
25
+ Kernel.warn "* and because of them, Celluloid doesn't work correctly"
26
+
27
+ Kernel.warn '* FFI blows up when libc is a LD script (ac63e07f7)'
12
28
  gem 'ffi', github: 'carpetsmoker/ffi', ref: 'ac63e07f7'
29
+
30
+ Kernel.warn '* Celluloid core detection blows up (7fdef04)'
13
31
  gem 'celluloid', github: 'celluloid/celluloid', ref: '7fdef04'
32
+
33
+ else
34
+ # handled by gemspec
14
35
  end
15
36
 
16
37
  group :tool do
data/Guardfile CHANGED
File without changes
File without changes
data/README.md CHANGED
@@ -156,7 +156,7 @@ Also, setting the environment variable `LISTEN_GEM_DEBUGGING=1` does the same as
156
156
  ## Listen adapters
157
157
 
158
158
  The Listen gem has a set of adapters to notify it when there are changes.
159
- There are 4 OS-specific adapters to support Darwin, Linux, ~~*BSD~~ and Windows.
159
+ There are 4 OS-specific adapters to support Darwin, Linux, ~~\*BSD~~ and Windows.
160
160
  These adapters are fast as they use some system-calls to implement the notifying function.
161
161
 
162
162
  There is also a polling adapter which is a cross-platform adapter and it will
@@ -178,11 +178,11 @@ require 'rbconfig'
178
178
  gem 'wdm', '>= 0.1.0' if RbConfig::CONFIG['target_os'] =~ /mswin|mingw|cygwin/i
179
179
  ```
180
180
 
181
- ### On *BSD
181
+ ### On \*BSD
182
182
 
183
- **NOTE: *BSD currently is BROKEN with no plans to fix it or support it (see: [#220](https://github.com/guard/listen/issues/220))**
183
+ **NOTE: \*BSD currently is BROKEN with no plans to fix it or support it (see: [#220](https://github.com/guard/listen/issues/220))**
184
184
 
185
- If your are on *BSD you can try to use the [`rb-kqueue`](https://github.com/mat813/rb-kqueue) instead of polling.
185
+ If your are on \*BSD you can try to use the [`rb-kqueue`](https://github.com/mat813/rb-kqueue) instead of polling.
186
186
  Please add the following to your Gemfile:
187
187
 
188
188
  ```ruby
@@ -199,13 +199,10 @@ end
199
199
 
200
200
  ```
201
201
 
202
- ### Issues
203
-
204
- Listen traps SIGINT signal to properly finalize listeners. If you plan
205
- on trapping this signal yourself - make sure to call `Listen.stop` in
206
- signal handler.
202
+ ### Issues and troubleshooting
207
203
 
208
204
  Sometimes OS-specific adapters don't work. :'(
205
+
209
206
  Here are some things you could try to avoid forcing polling.
210
207
 
211
208
  * [Update your Dropbox client](http://www.dropbox.com/downloading), if you have Dropbox installed.
@@ -216,7 +213,18 @@ Here are some things you could try to avoid forcing polling.
216
213
 
217
214
  If your application keeps using the polling-adapter and you can't figure out why, feel free to [open an issue](https://github.com/guard/listen/issues/new) (and be sure to [give all the details](https://github.com/guard/listen/blob/master/CONTRIBUTING.md)).
218
215
 
219
- Also, if you have problems related to receiving the wrong events, too many events or none at all, be sure set the environment variable `LISTEN_GEM_DEBUGGING=1` and include the output when reporting a new issue.
216
+ Also, if you have problems related to receiving the wrong events, too many
217
+ events or none at all, be sure set the environment variable
218
+ `LISTEN_GEM_DEBUGGING=1` and include the output when reporting a new issue.
219
+
220
+ If the listener works and then stops listening at some point and no errors are
221
+ shown with `LISTEN_GEM_DEBUGGING=1`, set `LISTEN_GEM_DEBUGGING=2` for full
222
+ logging.
223
+
224
+ Listen traps SIGINT signal to properly finalize listeners. If you plan
225
+ on trapping this signal yourself - make sure to call `Listen.stop` in
226
+ signal handler.
227
+
220
228
 
221
229
  ## Forwarding file events over TCP
222
230
 
data/Rakefile CHANGED
File without changes
@@ -25,8 +25,7 @@ module Listen
25
25
  @stopping = false
26
26
  options = args.last.is_a?(Hash) ? args.last : {}
27
27
  if target = options.delete(:forward_to)
28
- require 'listen/tcp'
29
- TCP::Listener.new(target, :broadcaster, *args, &block)
28
+ Listener.new(target, :broadcaster, *args, &block)
30
29
  else
31
30
  Listener.new(*args, &block)
32
31
  end
@@ -53,8 +52,7 @@ module Listen
53
52
  # @return [Listen::Listener] the listener
54
53
  #
55
54
  def on(target, *args, &block)
56
- require 'listen/tcp'
57
- TCP::Listener.new(target, :recipient, *args, &block)
55
+ Listener.new(target, :recipient, *args, &block)
58
56
  end
59
57
 
60
58
  private
@@ -7,29 +7,38 @@ require 'listen/adapter/windows'
7
7
 
8
8
  module Listen
9
9
  module Adapter
10
- OPTIMIZED_ADAPTERS = %w(Darwin Linux BSD Windows)
10
+ OPTIMIZED_ADAPTERS = [Darwin, Linux, BSD, Windows]
11
11
  POLLING_FALLBACK_MESSAGE = 'Listen will be polling for changes.'\
12
12
  'Learn more at https://github.com/guard/listen#polling-fallback.'
13
13
 
14
14
  def self.select(options = {})
15
+ _log :debug, 'Adapter: considering TCP ...'
15
16
  return TCP if options[:force_tcp]
17
+ _log :debug, 'Adapter: considering polling ...'
16
18
  return Polling if options[:force_polling]
19
+ _log :debug, 'Adapter: considering optimized backend...'
17
20
  return _usable_adapter_class if _usable_adapter_class
18
-
21
+ _log :debug, 'Adapter: falling back to polling...'
19
22
  _warn_polling_fallback(options)
20
23
  Polling
24
+ rescue
25
+ _log :warn, "Adapter: failed: #{$!.inspect}:#{$@.join("\n")}"
26
+ raise
21
27
  end
22
28
 
23
29
  private
24
30
 
25
31
  def self._usable_adapter_class
26
- adapters = OPTIMIZED_ADAPTERS.map { |adapter| Adapter.const_get(adapter) }
27
- adapters.detect { |adapter| adapter.send(:usable?) }
32
+ OPTIMIZED_ADAPTERS.detect(&:usable?)
28
33
  end
29
34
 
30
35
  def self._warn_polling_fallback(options)
31
36
  msg = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE)
32
37
  Kernel.warn "[Listen warning]:\n #{msg}" if msg
33
38
  end
39
+
40
+ def self._log(type, message)
41
+ Celluloid.logger.send(type, message)
42
+ end
34
43
  end
35
44
  end
@@ -3,41 +3,58 @@ module Listen
3
3
  class Base
4
4
  include Celluloid
5
5
 
6
- # The default delay between checking for changes.
7
- DEFAULT_LATENCY = 0.1
8
-
9
6
  attr_accessor :listener
10
7
 
11
8
  def initialize(listener)
12
9
  @listener = listener
13
- end
14
-
15
- def self.usable?
16
- fail NotImplementedError
10
+ rescue
11
+ _log :error, "adapter config failed: #{$!}:#{$@.join("\n")}"
12
+ raise
17
13
  end
18
14
 
19
15
  def start
20
- fail NotImplementedError
16
+ _configure
17
+ Thread.new do
18
+ begin
19
+ _run
20
+ rescue
21
+ _log :error, "run() in thread failed: #{$!}:#{$@.join("\n")}"
22
+ raise
23
+ end
24
+ end
21
25
  end
22
26
 
23
27
  def self.local_fs?
24
28
  true
25
29
  end
26
30
 
31
+ def self.usable?
32
+ const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os']
33
+ end
34
+
27
35
  private
28
36
 
29
- def _latency
30
- listener.options[:latency] || DEFAULT_LATENCY
37
+ def _configure
31
38
  end
32
39
 
33
- def _directories_path
34
- listener.directories.map(&:to_s)
40
+ def _directories
41
+ listener.directories
42
+ end
43
+
44
+ def _notify_change(type, path, options = {})
45
+ unless (worker = listener.async(:change_pool))
46
+ _log :warn, 'Failed to allocate worker from change pool'
47
+ return
48
+ end
49
+
50
+ worker.change(type, path, options)
51
+ rescue RuntimeError
52
+ _log :error, "_notify_change crashed: #{$!}:#{$@.join("\n")}"
53
+ raise
35
54
  end
36
55
 
37
- def _notify_change(path, options)
38
- sleep 0.01 until listener.registry[:change_pool]
39
- pool = listener.registry[:change_pool]
40
- pool.async.change(path, options) if listener.listen?
56
+ def _log(type, message)
57
+ Celluloid.logger.send(type, message)
41
58
  end
42
59
  end
43
60
  end
@@ -5,18 +5,14 @@
5
5
  module Listen
6
6
  module Adapter
7
7
  class BSD < Base
8
- # Watched kqueue events
9
- #
10
- EVENTS = [:delete, :write, :extend, :attrib, :rename] # :link, :revoke
8
+ OS_REGEXP = /bsd|dragonfly/i
11
9
 
12
- BSD_OS_REGEXP = /bsd|dragonfly/i
10
+ EVENTS = [:delete, :write, :extend, :attrib, :rename] # :link, :revoke
13
11
 
14
- # The message to show when wdm gem isn't available
15
- #
16
12
  BUNDLER_DECLARE_GEM = <<-EOS.gsub(/^ {6}/, '')
17
13
  Please add the following to your Gemfile to avoid polling for changes:
18
14
  require 'rbconfig'
19
- if RbConfig::CONFIG['target_os'] =~ #{BSD_OS_REGEXP}
15
+ if RbConfig::CONFIG['target_os'] =~ #{OS_REGEXP}
20
16
  gem 'rb-kqueue', '>= 0.2'
21
17
 
22
18
  # Base versions have known conflicts/bugs
@@ -39,56 +35,47 @@ module Listen
39
35
  EOS
40
36
 
41
37
  def self.usable?
42
- if RbConfig::CONFIG['target_os'] =~ BSD_OS_REGEXP
43
- Kernel.warn BSD_EXPERIMENTAL
44
- require 'rb-kqueue'
45
- require 'find'
46
- true
47
- end
38
+ return false unless super
39
+ Kernel.warn BSD_EXPERIMENTAL
40
+ require 'rb-kqueue'
41
+ require 'find'
42
+ true
48
43
  rescue LoadError
49
44
  Kernel.warn BUNDLER_DECLARE_GEM
50
45
  false
51
46
  end
52
47
 
53
- def start
54
- worker = _init_worker
55
- Thread.new { worker.run }
56
- end
57
-
58
48
  private
59
49
 
60
- # Initializes a kqueue Queue and adds a watcher for each files in
61
- # the directories passed to the adapter.
62
- #
63
- # @return [INotify::Notifier] initialized kqueue
64
- #
65
- def _init_worker
66
- KQueue::Queue.new.tap do |queue|
67
- _directories_path.each do |path|
68
- # use Record to make a snapshot of dir, so we
69
- # can detect new files
70
- _find(path) { |file_path| _watch_file(file_path, queue) }
71
- end
50
+ def _configure
51
+ @worker = KQueue::Queue.new
52
+ _directories.each do |path|
53
+ # use Record to make a snapshot of dir, so we
54
+ # can detect new files
55
+ _find(path.to_s) { |file_path| _watch_file(file_path, @worker) }
72
56
  end
73
57
  end
74
58
 
59
+ def _run
60
+ @worker.run
61
+ end
62
+
75
63
  def _worker_callback
76
64
  lambda do |event|
77
- change = _change(event.flags)
78
65
  path = _event_path(event)
79
66
  if path.directory?
80
67
  # Force dir content tracking to kick in, or we won't have
81
68
  # names of added files
82
- _notify_change(path, type: 'Directory', recursive: true)
69
+ _notify_change(:dir, path, recursive: true)
83
70
  else
84
- _notify_change(path, type: 'File', change: change)
71
+ _notify_change(:file, path, change: _change(event.flags))
85
72
  end
86
73
 
87
74
  # If it is a directory, and it has a write flag, it means a
88
75
  # file has been added so find out which and deal with it.
89
76
  # No need to check for removed files, kqueue will forget them
90
77
  # when the vfs does.
91
- _watch_for_new_file(event) if _new_file_added?(event)
78
+ _watch_for_new_file(event) if path.directory?
92
79
  end
93
80
  end
94
81
 
@@ -106,10 +93,6 @@ module Listen
106
93
  Pathname.new(event.watcher.path)
107
94
  end
108
95
 
109
- def _new_file_added?(event)
110
- ::File.directory?(event.watcher.path) && event.flags.include?(:write)
111
- end
112
-
113
96
  def _watch_for_new_file(event)
114
97
  queue = event.watcher.queue
115
98
  _find(_event_path(event).to_s) do |file_path|
@@ -3,39 +3,31 @@ module Listen
3
3
  # Adapter implementation for Mac OS X `FSEvents`.
4
4
  #
5
5
  class Darwin < Base
6
- def self.usable?
7
- RbConfig::CONFIG['target_os'] =~ /darwin(1.+)?$/i
8
- end
6
+ OS_REGEXP = /darwin(1.+)?$/i
9
7
 
10
- def initialize(listener)
11
- require 'rb-fsevent'
12
- super
13
- end
14
-
15
- def start
16
- worker = _init_worker
17
- Thread.new { worker.run }
18
- end
8
+ # The default delay between checking for changes.
9
+ DEFAULT_LATENCY = 0.1
19
10
 
20
11
  private
21
12
 
22
- # Initializes a FSEvent worker and adds a watcher for
23
- # each directory listened.
24
- #
25
- def _init_worker
26
- FSEvent.new.tap do |worker|
27
- worker.watch(_directories_path, latency: _latency) do |changes|
28
- paths = _changes_path(changes)
29
- paths.each { |path| _notify_change(path, type: 'Dir') }
13
+ def _configure
14
+ require 'rb-fsevent'
15
+ @worker = FSEvent.new
16
+ @worker.watch(_directories.map(&:to_s), latency: _latency) do |changes|
17
+ changes.each do |path|
18
+ new_path = Pathname.new(path.sub(/\/$/, ''))
19
+ _log :debug, "fsevent: #{new_path}"
20
+ _notify_change(:dir, new_path)
30
21
  end
31
22
  end
32
23
  end
33
24
 
34
- def _changes_path(changes)
35
- changes.map do |path|
36
- path.sub!(/\/$/, '')
37
- Pathname.new(path)
38
- end
25
+ def _run
26
+ @worker.run
27
+ end
28
+
29
+ def _latency
30
+ listener.options[:latency] || DEFAULT_LATENCY
39
31
  end
40
32
  end
41
33
  end
@@ -1,17 +1,13 @@
1
1
  module Listen
2
2
  module Adapter
3
3
  # Listener implementation for Linux `inotify`.
4
+ # @see https://github.com/nex3/rb-inotify
4
5
  #
5
6
  class Linux < Base
6
- # Watched inotify events
7
- #
8
- # @see http://www.tin.org/bin/man.cgi?section=7&topic=inotify
9
- # @see https://github.com/nex3/rb-inotify
10
- #
7
+ OS_REGEXP = /linux/i
8
+
11
9
  EVENTS = [:recursive, :attrib, :create, :delete, :move, :close_write]
12
10
 
13
- # The message to show when the limit of inotify watchers is not enough
14
- #
15
11
  WIKI_URL = 'https://github.com/guard/listen'\
16
12
  '/wiki/Increasing-the-amount-of-inotify-watchers'
17
13
 
@@ -22,53 +18,49 @@ module Listen
22
18
  for information on how to solve this issue.
23
19
  EOS
24
20
 
25
- def self.usable?
26
- RbConfig::CONFIG['target_os'] =~ /linux/i
27
- end
21
+ private
28
22
 
29
- def initialize(listener)
23
+ def _configure
30
24
  require 'rb-inotify'
31
- super
32
- end
33
-
34
- def start
35
- worker = _init_worker
36
- Thread.new { worker.run }
25
+ @worker = INotify::Notifier.new
26
+ _directories.each do |path|
27
+ @worker.watch(path.to_s, *EVENTS, &_callback)
28
+ end
37
29
  rescue Errno::ENOSPC
30
+ # workaround - Celluloid catches abort and prints nothing
38
31
  STDERR.puts INOTIFY_LIMIT_MESSAGE
39
32
  STDERR.flush
40
33
  abort(INOTIFY_LIMIT_MESSAGE)
41
34
  end
42
35
 
43
- private
44
-
45
- # Initializes a INotify worker and adds a watcher for
46
- # each directory passed to the adapter.
47
- #
48
- # @return [INotify::Notifier] initialized worker
49
- #
50
- def _init_worker
51
- INotify::Notifier.new.tap do |worker|
52
- _directories_path.each do |path|
53
- worker.watch(path, *EVENTS, &_worker_callback)
54
- end
55
- end
36
+ def _run
37
+ @worker.run
56
38
  end
57
39
 
58
- def _worker_callback
40
+ def _callback
59
41
  lambda do |event|
60
- next if _skip_event?(event)
61
-
62
- path = _event_path(event)
63
- cookie_opts = event.cookie.zero? ? {} : { cookie: event.cookie }
64
-
65
- _log(event)
66
-
67
- if _dir_event?(event)
68
- _notify_change(path, { type: 'Dir' }.merge(cookie_opts))
42
+ # NOTE: avoid using event.absolute_name since new API
43
+ # will need to have a custom recursion implemented
44
+ # to properly match events to configured directories
45
+ path = Pathname.new(event.watcher.path) + event.name
46
+
47
+ _log :debug, "inotify: #{event.name} #{path} (#{event.flags.inspect})"
48
+
49
+ if /1|true/ =~ ENV['LISTEN_GEM_SIMULATE_FSEVENT']
50
+ if (event.flags & [:moved_to, :moved_from]) || _dir_event?(event)
51
+ _notify_change(:dir, path.dirname)
52
+ else
53
+ _notify_change(:dir, path)
54
+ end
69
55
  else
70
- options = { type: 'File', change: _change(event.flags) }
71
- _notify_change(path, options.merge(cookie_opts))
56
+ next if _skip_event?(event)
57
+ cookie_opts = event.cookie.zero? ? {} : { cookie: event.cookie }
58
+ if _dir_event?(event)
59
+ _notify_change(:dir, path, cookie_opts)
60
+ else
61
+ options = { change: _change(event.flags) }
62
+ _notify_change(:file, path, options.merge(cookie_opts))
63
+ end
72
64
  end
73
65
  end
74
66
  end
@@ -97,16 +89,6 @@ module Listen
97
89
  def _dir_event?(event)
98
90
  event.flags.include?(:isdir)
99
91
  end
100
-
101
- def _event_path(event)
102
- Pathname.new(event.absolute_name)
103
- end
104
-
105
- def _log(event)
106
- name = event.name
107
- flags = event.flags.inspect
108
- Celluloid.logger.info "inotify event: #{flags}: #{name}"
109
- end
110
92
  end
111
93
  end
112
94
  end