listen 3.3.1 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e11b5e927f693205d422a0ea65147a53f65b08acde3a5dec7b370ac3f66b9707
4
- data.tar.gz: 29bf36d64485cbbdc806451381d402067796430d8a5cd6ca1903a394d73d2c84
3
+ metadata.gz: 177b9383bf2b074aa676e65740451122818a165210268172b091a5528054dcde
4
+ data.tar.gz: cf3e77517acd2ce09a140c34a7349eedad081d4b4bc8e0f4e80cefd35ce9363f
5
5
  SHA512:
6
- metadata.gz: 18fa31e48db9c6b9f99108e2dabed785ba15409d0d79b3b2bbcc47be0ea6c55b82418e44ce48639b32fe137fa0871623b8e593c1ffbaeee18fa4847c484cd3d9
7
- data.tar.gz: a2cec7e23abba56a0b47e2f736d8fe37cb01a574da6a54049156eace74af67cf3783f2cbded1f7a2778ae1e26bbc75342144f2c16b05a30ced06ad7f91fa4e9e
6
+ metadata.gz: c2d73e033027eb1f2fa455a180e7abbf344bb2889ad9af7b1d79a111d55c00b4f8481c080c94ca06d8383da6ef45481e47434a25b03aba75c74839b37bf4e8b4
7
+ data.tar.gz: 30c3da7656d66f93ac25fc4202ef15bb813fdb6c4a7c90221ecdd49f32b267826082c4af20275454f0ada71e790ef5ac5ea20275302c66de5dedc36dc3bcb05d
@@ -4,7 +4,7 @@ Contribute to Listen
4
4
  File an issue
5
5
  -------------
6
6
 
7
- If you haven't already, first see [TROUBLESHOOTING](https://github.com/guard/listen/wiki/Troubleshooting) for known issues, solutions and workarounds.
7
+ If you haven't already, first see [TROUBLESHOOTING](https://github.com/guard/listen/blob/master/README.md#Issues-and-Troubleshooting) for known issues, solutions and workarounds.
8
8
 
9
9
  You can report bugs and feature requests to [GitHub Issues](https://github.com/guard/listen/issues).
10
10
 
@@ -16,7 +16,7 @@ Try to figure out where the issue belongs to: Is it an issue with Listen itself
16
16
 
17
17
  **It's most likely that your bug gets resolved faster if you provide as much information as possible!**
18
18
 
19
- The MOST useful information is debugging output from Listen (`LISTEN_GEM_DEBUGGING=1`) - see [TROUBLESHOOTING](https://github.com/guard/listen/wiki/Troubleshooting) for details.
19
+ The MOST useful information is debugging output from Listen (`LISTEN_GEM_DEBUGGING=1`) - see [TROUBLESHOOTING](https://github.com/guard/listen/blob/master/README.md#Issues-and-Troubleshooting) for details.
20
20
 
21
21
 
22
22
  Development
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  The `listen` gem listens to file modifications and notifies you about the changes.
4
4
 
5
- :exclamation: `Listen` is currently accepting more maintainers. Please [read this](https://github.com/guard/guard/wiki/Maintainers) if you're interested in joining the team.
6
-
7
5
  [![Development Status](https://github.com/guard/listen/workflows/Development/badge.svg)](https://github.com/guard/listen/actions?workflow=Development)
8
6
  [![Gem Version](https://badge.fury.io/rb/listen.svg)](http://badge.fury.io/rb/listen)
9
7
  [![Code Climate](https://codeclimate.com/github/guard/listen.svg)](https://codeclimate.com/github/guard/listen)
@@ -22,7 +20,7 @@ The `listen` gem listens to file modifications and notifies you about the change
22
20
 
23
21
  * Limited support for symlinked directories ([#279](https://github.com/guard/listen/issues/279)):
24
22
  * Symlinks are always followed ([#25](https://github.com/guard/listen/issues/25)).
25
- * Symlinked directories pointing within a watched directory are not supported ([#273](https://github.com/guard/listen/pull/273)- see [Duplicate directory errors](https://github.com/guard/listen/wiki/Duplicate-directory-errors)).
23
+ * Symlinked directories pointing within a watched directory are not supported ([#273](https://github.com/guard/listen/pull/273).
26
24
  * No directory/adapter-specific configuration options.
27
25
  * Support for plugins planned for future.
28
26
  * TCP functionality was removed in `listen` [3.0.0](https://github.com/guard/listen/releases/tag/v3.0.0) ([#319](https://github.com/guard/listen/issues/319), [#218](https://github.com/guard/listen/issues/218)). There are plans to extract this feature to separate gems ([#258](https://github.com/guard/listen/issues/258)), until this is finished, you can use by locking the `listen` gem to version `'~> 2.10'`.
@@ -40,7 +38,7 @@ Pull requests or help is very welcome for these.
40
38
  The simplest way to install `listen` is to use [Bundler](http://bundler.io).
41
39
 
42
40
  ```ruby
43
- gem 'listen', '~> 3.3' # NOTE: for TCP functionality, use '~> 2.10' for now
41
+ gem 'listen'
44
42
  ```
45
43
 
46
44
  ## Complete Example
@@ -240,7 +238,7 @@ If you are on Windows, it's recommended to use the [`wdm`](https://github.com/Ma
240
238
  Please add the following to your Gemfile:
241
239
 
242
240
  ```ruby
243
- gem 'wdm', '>= 0.1.0' if Gem.win_platform?
241
+ gem 'wdm', '>= 0.1.0', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
244
242
  ```
245
243
 
246
244
  ### On \*BSD
@@ -259,7 +257,82 @@ end
259
257
 
260
258
  ### Getting the [polling fallback message](#options)?
261
259
 
262
- Please visit the [installation section of the Listen WIKI](https://github.com/guard/listen/wiki#installation) for more information and options for potential fixes.
260
+ If you see:
261
+ ```
262
+ Listen will be polling for changes.
263
+ ```
264
+
265
+ This means the Listen gem can’t find an optimized adapter. Typically this is caused by:
266
+
267
+ - You’re on Windows and WDM gem isn’t installed.
268
+ - You’re running the app without Bundler or RubyGems.
269
+ - Using Sass which includes an ancient (the “dinosaur” type of ancient) version of the Listen gem.
270
+
271
+ Possible solutions:
272
+
273
+ 1. Suppress the message by using the :force_polling option. Or, you could just ignore the message since it’s harmless.
274
+ 2. Windows users: Install the WDM gem.
275
+ 3. Upgrade Ruby (use RubyInstaller for Windows or RVM/rbenv for Mac) and RubyGems.
276
+ 3. Run your apps using Bundler.
277
+ 4. Sass users: Install the latest version of Listen and try again.
278
+
279
+ #### Simplified Bundler and Sass example
280
+ Create a Gemfile with these lines:
281
+ ```
282
+ source 'https://rubygems.org'
283
+ gem 'listen'
284
+ gem 'sass'
285
+ ```
286
+ Next, use Bundler to update gems:
287
+ ```
288
+ $ bundle update
289
+ $ bundle exec sass --watch # ... or whatever app is using Listen.
290
+ ```
291
+
292
+ ### Increasing the amount of inotify watchers
293
+
294
+ If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal:
295
+ ```
296
+ $ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
297
+ $ sudo sysctl -p
298
+ ```
299
+ If you are running ArchLinux, search the `/etc/sysctl.d/` directory for config files with the setting:
300
+ ```
301
+ $ grep -H -s "fs.inotify.max_user_watches" /etc/sysctl.d/*
302
+ /etc/sysctl.d/40-max_user_watches.conf:fs.inotify.max_user_watches=100000
303
+ ```
304
+ Then change the setting in the file you found above to a higher value (see [here](https://www.archlinux.org/news/deprecation-of-etcsysctlconf/) for why):
305
+ ```
306
+ $ sudo sh -c "echo fs.inotify.max_user_watches=524288 > /etc/sysctl.d/40-max-user-watches.conf"
307
+ $ sudo sysctl --system
308
+ ```
309
+
310
+ #### The technical details
311
+ Listen uses `inotify` by default on Linux to monitor directories for changes.
312
+ It's not uncommon to encounter a system limit on the number of files you can monitor.
313
+ For example, Ubuntu Lucid's (64bit) `inotify` limit is set to 8192.
314
+
315
+ You can get your current inotify file watch limit by executing:
316
+ ```
317
+ $ cat /proc/sys/fs/inotify/max_user_watches
318
+ ```
319
+ When this limit is not enough to monitor all files inside a directory, the limit must be increased for Listen to work properly.
320
+
321
+ You can set a new limit temporarily with:
322
+ ```
323
+ $ sudo sysctl fs.inotify.max_user_watches=524288
324
+ $ sudo sysctl -p
325
+ ```
326
+ If you like to make your limit permanent, use:
327
+ ```
328
+ $ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
329
+ $ sudo sysctl -p
330
+ ```
331
+ You may also need to pay attention to the values of `max_queued_events` and `max_user_instances` if Listen keeps on complaining.
332
+
333
+ #### More info
334
+ Man page for [inotify(7)](https://linux.die.net/man/7/inotify).
335
+ Blog post: [limit of inotify](https://blog.sorah.jp/2012/01/24/inotify-limitation).
263
336
 
264
337
  ### Issues and Troubleshooting
265
338
 
@@ -267,7 +340,35 @@ If the gem doesn't work as expected, start by setting `LISTEN_GEM_DEBUGGING=debu
267
340
 
268
341
  *NOTE: without providing the output after setting the `LISTEN_GEM_DEBUGGING=debug` environment variable, it is usually impossible to guess why `listen` is not working as expected.*
269
342
 
270
- See [TROUBLESHOOTING](https://github.com/guard/listen/wiki/Troubleshooting)
343
+ #### 3 steps before you start diagnosing problems
344
+ These 3 steps will:
345
+
346
+ - help quickly troubleshoot obscure problems (trust me, most of them are obscure)
347
+ - help quickly identify the area of the problem (a full list is below)
348
+ - help you get familiar with listen's diagnostic mode (it really comes in handy, trust me)
349
+ - help you create relevant output before you submit an issue (so we can respond with answers instead of tons of questions)
350
+
351
+ Step 1 - The most important option in Listen
352
+ For effective troubleshooting set the `LISTEN_GEM_DEBUGGING=info` variable before starting `listen`.
353
+
354
+ Step 2 - Verify polling works
355
+ Polling has to work ... or something is really wrong (and we need to know that before anything else).
356
+
357
+ (see force_polling option).
358
+
359
+ After starting `listen`, you should see something like:
360
+ ```
361
+ INFO -- : Record.build(): 0.06773114204406738 seconds
362
+ ```
363
+ Step 3 - Trigger some changes directly without using editors or apps
364
+ Make changes e.g. touch foo or echo "a" >> foo (for troubleshooting, avoid using an editor which could generate too many misleading events).
365
+
366
+ You should see something like:
367
+ ```
368
+ INFO -- : listen: raw changes: [[:added, "/home/me/foo"]]
369
+ INFO -- : listen: final changes: {:modified=>[], :added=>["/home/me/foo"], :removed=>[]}
370
+ ```
371
+ "raw changes" contains changes collected during the :wait_for_delay and :latency intervals, while "final changes" is what listen decided are relevant changes (for better editor support).
271
372
 
272
373
  ## Performance
273
374
 
@@ -289,7 +390,11 @@ Also, if the directories you're watching contain many files, make sure you're:
289
390
 
290
391
  When in doubt, `LISTEN_GEM_DEBUGGING=debug` can help discover the actual events and time they happened.
291
392
 
292
- See also [Tips and Techniques](https://github.com/guard/listen/wiki/Tips-and-Techniques).
393
+ ## Tips and Techniques
394
+ - Watch only directories you're interested in.
395
+ - Set your editor to save quickly (e.g. without backup files, without atomic-save)
396
+ - Tweak the `:latency` and `:wait_for_delay` options until you get good results (see [options](#options)).
397
+ - Add `:ignore` rules to silence all events you don't care about (reduces a lot of noise, especially if you use it on directories)
293
398
 
294
399
  ## Development
295
400
 
data/bin/listen CHANGED
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'listen'
4
5
  require 'listen/cli'
5
6
 
6
- unless defined?(JRUBY_VERSION)
7
- if Signal.list.keys.include?('INT')
8
- Signal.trap('INT') { Thread.new { Listen.stop } }
9
- end
7
+ if !defined?(JRUBY_VERSION) && Signal.list.keys.include?('INT')
8
+ Signal.trap('INT') { Thread.new { Listen.stop } }
10
9
  end
11
10
 
12
11
  Listen::CLI.start
@@ -11,7 +11,7 @@ module Listen
11
11
  module Adapter
12
12
  OPTIMIZED_ADAPTERS = [Darwin, Linux, BSD, Windows].freeze
13
13
  POLLING_FALLBACK_MESSAGE = 'Listen will be polling for changes.'\
14
- 'Learn more at https://github.com/guard/listen#listen-adapters.'.freeze
14
+ 'Learn more at https://github.com/guard/listen#listen-adapters.'
15
15
 
16
16
  class << self
17
17
  def select(options = {})
@@ -24,14 +24,14 @@ module Listen
24
24
  Polling
25
25
  rescue
26
26
  Listen.logger.warn format('Adapter: failed: %s:%s', $ERROR_POSITION.inspect,
27
- $ERROR_POSITION * "\n")
27
+ $ERROR_POSITION * "\n")
28
28
  raise
29
29
  end
30
30
 
31
31
  private
32
32
 
33
33
  def _usable_adapter_class
34
- OPTIMIZED_ADAPTERS.detect(&:usable?)
34
+ OPTIMIZED_ADAPTERS.find(&:usable?)
35
35
  end
36
36
 
37
37
  def _warn_polling_fallback(options)
@@ -8,13 +8,11 @@ require 'listen/thread'
8
8
  module Listen
9
9
  module Adapter
10
10
  class Base
11
- attr_reader :options
11
+ attr_reader :options, :config
12
12
 
13
13
  # TODO: only used by tests
14
14
  DEFAULTS = {}.freeze
15
15
 
16
- attr_reader :config
17
-
18
16
  def initialize(config)
19
17
  @started = false
20
18
  @config = config
@@ -31,6 +29,7 @@ module Listen
31
29
  end
32
30
 
33
31
  # TODO: it's a separate method as a temporary workaround for tests
32
+ # rubocop:disable Metrics/MethodLength
34
33
  def configure
35
34
  if @configured
36
35
  Listen.logger.warn('Adapter already configured!')
@@ -57,6 +56,7 @@ module Listen
57
56
  @snapshots[dir] = snapshot
58
57
  end
59
58
  end
59
+ # rubocop:enable Metrics/MethodLength
60
60
 
61
61
  def started?
62
62
  @started
@@ -73,7 +73,7 @@ module Listen
73
73
  @started = true
74
74
 
75
75
  @run_thread = Listen::Thread.new("run_thread") do
76
- @snapshots.values.each do |snapshot|
76
+ @snapshots.each_value do |snapshot|
77
77
  _timed('Record.build()') { snapshot.record.build }
78
78
  end
79
79
  _run
@@ -93,9 +93,9 @@ module Listen
93
93
  end
94
94
 
95
95
  def _timed(title)
96
- start = Time.now.to_f
96
+ start = MonotonicTime.now
97
97
  yield
98
- diff = Time.now.to_f - start
98
+ diff = MonotonicTime.now - start
99
99
  Listen.logger.info format('%s: %.05f seconds', title, diff)
100
100
  rescue
101
101
  Listen.logger.warn "#{title} crashed: #{$ERROR_INFO.inspect}"
@@ -7,7 +7,7 @@
7
7
  module Listen
8
8
  module Adapter
9
9
  class BSD < Base
10
- OS_REGEXP = /bsd|dragonfly/i
10
+ OS_REGEXP = /bsd|dragonfly/i.freeze
11
11
 
12
12
  DEFAULTS = {
13
13
  events: [
@@ -73,8 +73,7 @@ module Listen
73
73
  def _change(event_flags)
74
74
  { modified: [:attrib, :extend],
75
75
  added: [:write],
76
- removed: [:rename, :delete]
77
- }.each do |change, flags|
76
+ removed: [:rename, :delete] }.each do |change, flags|
78
77
  return change unless (flags & event_flags).empty?
79
78
  end
80
79
  nil
@@ -87,7 +86,7 @@ module Listen
87
86
  def _watch_for_new_file(event)
88
87
  queue = event.watcher.queue
89
88
  _find(_event_path(event).to_s) do |file_path|
90
- unless queue.watchers.detect { |_, v| v.path == file_path.to_s }
89
+ unless queue.watchers.find { |_, v| v.path == file_path.to_s }
91
90
  _watch_file(file_path, queue)
92
91
  end
93
92
  end
@@ -5,10 +5,7 @@ require 'pathname'
5
5
  module Listen
6
6
  module Adapter
7
7
  class Config
8
- attr_reader :directories
9
- attr_reader :silencer
10
- attr_reader :queue
11
- attr_reader :adapter_options
8
+ attr_reader :directories, :silencer, :queue, :adapter_options
12
9
 
13
10
  def initialize(directories, queue, silencer, adapter_options)
14
11
  # Default to current directory if no directories are supplied
@@ -7,7 +7,7 @@ module Listen
7
7
  # Adapter implementation for Mac OS X `FSEvents`.
8
8
  #
9
9
  class Darwin < Base
10
- OS_REGEXP = /darwin(?<major_version>(1|2)\d+)/i
10
+ OS_REGEXP = /darwin(?<major_version>(1|2)\d+)/i.freeze
11
11
 
12
12
  # The default delay between checking for changes.
13
13
  DEFAULTS = { latency: 0.1 }.freeze
@@ -51,7 +51,7 @@ module Listen
51
51
 
52
52
  def _process_changes(dirs)
53
53
  dirs.each do |dir|
54
- dir = Pathname.new(dir.sub(%r{\/$}, ''))
54
+ dir = Pathname.new(dir.sub(%r{/$}, ''))
55
55
 
56
56
  @callbacks.each do |watched_dir, callback|
57
57
  if watched_dir.eql?(dir) || Listen::Directory.ascendant_of?(watched_dir, dir)
@@ -4,7 +4,7 @@ module Listen
4
4
  module Adapter
5
5
  # @see https://github.com/nex3/rb-inotify
6
6
  class Linux < Base
7
- OS_REGEXP = /linux/i
7
+ OS_REGEXP = /linux/i.freeze
8
8
 
9
9
  DEFAULTS = {
10
10
  events: [
@@ -21,12 +21,12 @@ module Listen
21
21
 
22
22
  private
23
23
 
24
- WIKI_URL = 'https://github.com/guard/listen'\
25
- '/wiki/Increasing-the-amount-of-inotify-watchers'.freeze
24
+ README_URL = 'https://github.com/guard/listen'\
25
+ '/blob/master/README.md#increasing-the-amount-of-inotify-watchers'
26
26
 
27
- INOTIFY_LIMIT_MESSAGE = <<-EOS.gsub(/^\s*/, '')
27
+ INOTIFY_LIMIT_MESSAGE = <<-EOS
28
28
  FATAL: Listen error: unable to monitor directories for changes.
29
- Visit #{WIKI_URL} for info on how to fix this.
29
+ Visit #{README_URL} for info on how to fix this.
30
30
  EOS
31
31
 
32
32
  def _configure(directory, &callback)
@@ -41,6 +41,7 @@ module Listen
41
41
  @worker.run
42
42
  end
43
43
 
44
+ # rubocop:disable Metrics/MethodLength
44
45
  def _process_event(dir, event)
45
46
  # NOTE: avoid using event.absolute_name since new API
46
47
  # will need to have a custom recursion implemented
@@ -73,6 +74,7 @@ module Listen
73
74
 
74
75
  _queue_change(:file, dir, rel_path, params)
75
76
  end
77
+ # rubocop:enable Metrics/MethodLength
76
78
 
77
79
  def _skip_event?(event)
78
80
  # Event on root directory
@@ -8,7 +8,7 @@ module Listen
8
8
  # file IO than the other implementations.
9
9
  #
10
10
  class Polling < Base
11
- OS_REGEXP = // # match every OS
11
+ OS_REGEXP = //.freeze # match every OS
12
12
 
13
13
  DEFAULTS = { latency: 1.0, wait_for_delay: 0.05 }.freeze
14
14
 
@@ -21,12 +21,13 @@ module Listen
21
21
 
22
22
  def _run
23
23
  loop do
24
- start = Time.now.to_f
24
+ start = MonotonicTime.now
25
25
  @polling_callbacks.each do |callback|
26
26
  callback.call(nil)
27
- nap_time = options.latency - (Time.now.to_f - start)
28
- # TODO: warn if nap_time is negative (polling too slow)
29
- sleep(nap_time) if nap_time > 0
27
+ if (nap_time = options.latency - (MonotonicTime.now - start)) > 0
28
+ # TODO: warn if nap_time is negative (polling too slow)
29
+ sleep(nap_time)
30
+ end
30
31
  end
31
32
  end
32
33
  end
@@ -5,7 +5,7 @@ module Listen
5
5
  # Adapter implementation for Windows `wdm`.
6
6
  #
7
7
  class Windows < Base
8
- OS_REGEXP = /mswin|mingw|cygwin/i
8
+ OS_REGEXP = /mswin|mingw|cygwin/i.freeze
9
9
 
10
10
  BUNDLER_DECLARE_GEM = <<-EOS.gsub(/^ {6}/, '')
11
11
  Please add the following to your Gemfile to avoid polling for changes:
@@ -18,7 +18,7 @@ module Listen
18
18
  true
19
19
  rescue LoadError
20
20
  Listen.logger.debug format('wdm - load failed: %s:%s', $ERROR_INFO,
21
- $ERROR_POSITION * "\n")
21
+ $ERROR_POSITION * "\n")
22
22
 
23
23
  Kernel.warn BUNDLER_DECLARE_GEM
24
24
  false
@@ -38,8 +38,7 @@ module Listen
38
38
  yield([:dir, change])
39
39
  end
40
40
 
41
- events = [:attributes, :last_write]
42
- @worker.watch_recursively(dir.to_s, *events) do |change|
41
+ @worker.watch_recursively(dir.to_s, :attributes, :last_write) do |change|
43
42
  yield([:attr, change])
44
43
  end
45
44
  end
@@ -48,6 +47,7 @@ module Listen
48
47
  @worker.run!
49
48
  end
50
49
 
50
+ # rubocop:disable Metrics/MethodLength
51
51
  def _process_event(dir, event)
52
52
  Listen.logger.debug "wdm - callback: #{event.inspect}"
53
53
 
@@ -67,10 +67,11 @@ module Listen
67
67
  _queue_change(:file, dir, rel_path, options)
68
68
  end
69
69
  when :dir
70
- if change.type == :removed
70
+ case change.type
71
+ when :removed
71
72
  # TODO: check if watched dir?
72
73
  _queue_change(:dir, dir, Pathname(rel_path).dirname.to_s, {})
73
- elsif change.type == :added
74
+ when :added
74
75
  _queue_change(:dir, dir, rel_path, {})
75
76
  # do nothing - changed directory means either:
76
77
  # - removed subdirs (handled above)
@@ -80,20 +81,15 @@ module Listen
80
81
  # so what's left?
81
82
  end
82
83
  end
83
- rescue
84
- details = event.inspect
85
- Listen.logger.error format('wdm - callback (%s): %s:%s', details, $ERROR_INFO,
86
- $ERROR_POSITION * "\n")
87
- raise
88
84
  end
85
+ # rubocop:enable Metrics/MethodLength
89
86
 
90
87
  def _change(type)
91
88
  { modified: [:modified, :attrib], # TODO: is attrib really passed?
92
89
  added: [:added, :renamed_new_file],
93
- removed: [:removed, :renamed_old_file] }.each do |change, types|
94
- return change if types.include?(type)
90
+ removed: [:removed, :renamed_old_file] }.find do |change, types|
91
+ types.include?(type) and break change
95
92
  end
96
- nil
97
93
  end
98
94
  end
99
95
  end