listen 0.5.3 → 3.7.1

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 (48) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -186
  3. data/CONTRIBUTING.md +45 -0
  4. data/{LICENSE → LICENSE.txt} +3 -1
  5. data/README.md +332 -181
  6. data/bin/listen +11 -0
  7. data/lib/listen/adapter/base.rb +129 -0
  8. data/lib/listen/adapter/bsd.rb +107 -0
  9. data/lib/listen/adapter/config.rb +25 -0
  10. data/lib/listen/adapter/darwin.rb +77 -0
  11. data/lib/listen/adapter/linux.rb +108 -0
  12. data/lib/listen/adapter/polling.rb +40 -0
  13. data/lib/listen/adapter/windows.rb +96 -0
  14. data/lib/listen/adapter.rb +32 -201
  15. data/lib/listen/backend.rb +40 -0
  16. data/lib/listen/change.rb +69 -0
  17. data/lib/listen/cli.rb +65 -0
  18. data/lib/listen/directory.rb +93 -0
  19. data/lib/listen/error.rb +11 -0
  20. data/lib/listen/event/config.rb +40 -0
  21. data/lib/listen/event/loop.rb +94 -0
  22. data/lib/listen/event/processor.rb +126 -0
  23. data/lib/listen/event/queue.rb +54 -0
  24. data/lib/listen/file.rb +95 -0
  25. data/lib/listen/fsm.rb +133 -0
  26. data/lib/listen/listener/config.rb +41 -0
  27. data/lib/listen/listener.rb +93 -160
  28. data/lib/listen/logger.rb +36 -0
  29. data/lib/listen/monotonic_time.rb +27 -0
  30. data/lib/listen/options.rb +26 -0
  31. data/lib/listen/queue_optimizer.rb +129 -0
  32. data/lib/listen/record/entry.rb +66 -0
  33. data/lib/listen/record/symlink_detector.rb +41 -0
  34. data/lib/listen/record.rb +123 -0
  35. data/lib/listen/silencer/controller.rb +50 -0
  36. data/lib/listen/silencer.rb +106 -0
  37. data/lib/listen/thread.rb +54 -0
  38. data/lib/listen/version.rb +3 -1
  39. data/lib/listen.rb +40 -32
  40. metadata +87 -38
  41. data/lib/listen/adapters/darwin.rb +0 -85
  42. data/lib/listen/adapters/linux.rb +0 -113
  43. data/lib/listen/adapters/polling.rb +0 -67
  44. data/lib/listen/adapters/windows.rb +0 -87
  45. data/lib/listen/dependency_manager.rb +0 -126
  46. data/lib/listen/directory_record.rb +0 -344
  47. data/lib/listen/multi_listener.rb +0 -121
  48. data/lib/listen/turnstile.rb +0 -28
data/README.md CHANGED
@@ -1,269 +1,400 @@
1
- # Listen [![Build Status](https://secure.travis-ci.org/guard/listen.png?branch=master)](http://travis-ci.org/guard/listen)
1
+ # Listen
2
2
 
3
- The Listen gem listens to file modifications and notifies you about the changes.
3
+ The `listen` gem listens to file modifications and notifies you about the changes.
4
+
5
+ [![Development Status](https://github.com/guard/listen/workflows/Development/badge.svg)](https://github.com/guard/listen/actions?workflow=Development)
6
+ [![Gem Version](https://badge.fury.io/rb/listen.svg)](http://badge.fury.io/rb/listen)
7
+ [![Code Climate](https://codeclimate.com/github/guard/listen.svg)](https://codeclimate.com/github/guard/listen)
8
+ [![Coverage Status](https://coveralls.io/repos/guard/listen/badge.svg?branch=master)](https://coveralls.io/r/guard/listen)
4
9
 
5
10
  ## Features
6
11
 
7
- * Works everywhere!
8
- * Supports watching multiple directories from a single listener.
9
- * OS-specific adapters for Mac OS X 10.6+, Linux and Windows.
10
- * Automatic fallback to polling if OS-specific adapter doesn't work.
12
+ * OS-optimized adapters on MRI for Mac OS X 10.6+, Linux, \*BSD and Windows, [more info](#listen-adapters) below.
11
13
  * Detects file modification, addition and removal.
12
- * Checksum comparison for modifications made under the same second.
13
- * Allows supplying regexp-patterns to ignore and filter paths for better results.
14
- * Tested on all Ruby environments via [travis-ci](http://travis-ci.org/guard/listen).
14
+ * You can watch multiple directories.
15
+ * Regexp-patterns for ignoring paths for more accuracy and speed
16
+ * Increased change detection accuracy on OS X HFS and VFAT volumes.
17
+ * Continuous Integration: tested on selected Ruby environments via [Github Workflows](https:///github.com/guard/listen/master/.github/workflows).
18
+
19
+ ## Issues / limitations
20
+
21
+ * Limited support for symlinked directories ([#279](https://github.com/guard/listen/issues/279)):
22
+ * Symlinks are always followed ([#25](https://github.com/guard/listen/issues/25)).
23
+ * Symlinked directories pointing within a watched directory are not supported ([#273](https://github.com/guard/listen/pull/273).
24
+ * No directory/adapter-specific configuration options.
25
+ * Support for plugins planned for future.
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'`.
27
+ * Some filesystems won't work without polling (VM/Vagrant Shared folders, NFS, Samba, sshfs, etc.).
28
+ * Windows and \*BSD adapter aren't continuously and automatically tested.
29
+ * OSX adapter has some performance limitations ([#342](https://github.com/guard/listen/issues/342)).
30
+ * Listeners do not notify across forked processes, if you wish for multiple processes to receive change notifications you must [listen inside of each process](https://github.com/guard/listen/issues/398#issuecomment-223957952).
31
+
32
+ Pull requests or help is very welcome for these.
15
33
 
16
34
  ## Install
17
35
 
18
- ``` bash
19
- gem install listen
36
+ The simplest way to install `listen` is to use [Bundler](http://bundler.io).
37
+
38
+ ```ruby
39
+ gem 'listen'
20
40
  ```
21
41
 
22
- ## Usage
42
+ ## Complete Example
43
+ Here is a complete example of using the `listen` gem:
44
+ ```ruby
45
+ require 'listen'
46
+
47
+ listener = Listen.to('/srv/app') do |modified, added, removed|
48
+ puts(modified: modified, added: added, removed: removed)
49
+ end
50
+ listener.start
51
+ sleep
52
+ ```
53
+ Running the above in the background, you can see the callback block being called in response to each command:
54
+ ```
55
+ $ cd /srv/app
56
+ $ touch a.txt
57
+ {:modified=>[], :added=>["/srv/app/a.txt"], :removed=>[]}
58
+
59
+ $ echo more >> a.txt
60
+ {:modified=>["/srv/app/a.txt"], :added=>[], :removed=>[]}
23
61
 
24
- There are **two ways** to use Listen:
62
+ $ mv a.txt b.txt
63
+ {:modified=>[], :added=>["/srv/app/b.txt"], :removed=>["/srv/app/a.txt"]}
25
64
 
26
- 1. Call `Listen.to` with either a single directory or multiple directories, then define the `change` callback in a block.
27
- 2. Create a `listener` object and use it in an (ARel style) chainable way.
65
+ $ vi b.txt
66
+ # add a line to this new file and press ZZ to save and exit
67
+ {:modified=>["/srv/app/b.txt"], :added=>[], :removed=>[]}
28
68
 
29
- Feel free to give your feeback via [Listen issues](https://github.com/guard/listen/issues)
69
+ $ vi c.txt
70
+ # add a line and press ZZ to save and exit
71
+ {:modified=>[], :added=>["/srv/app/c.txt"], :removed=>[]}
30
72
 
31
- ### Block API
73
+ $ rm b.txt c.txt
74
+ {:modified=>[], :added=>[], :removed=>["/srv/app/b.txt", "/srv/app/c.txt"]}
75
+ ```
76
+
77
+ ## Usage
78
+
79
+ Call `Listen.to` with one or more directories and the "changes" callback passed as a block.
32
80
 
33
81
  ``` ruby
34
- # Listen to a single directory.
35
- Listen.to('dir/path/to/listen', :filter => /\.rb$/, :ignore => %r{ignored/path/}) do |modified, added, removed|
36
- # ...
82
+ listener = Listen.to('dir/to/listen', 'dir/to/listen2') do |modified, added, removed|
83
+ puts "modified absolute path array: #{modified}"
84
+ puts "added absolute path array: #{added}"
85
+ puts "removed absolute path array: #{removed}"
37
86
  end
87
+ listener.start # starts a listener thread--does not block
38
88
 
39
- # Listen to multiple directories.
40
- Listen.to('dir/to/awesome_app', 'dir/to/other_app', :filter => /\.rb$/, :latency => 0.1) do |modified, added, removed|
41
- # ...
42
- end
89
+ # do whatever you want here...just don't exit the process :)
90
+
91
+ sleep
43
92
  ```
93
+ ## Changes Callback
94
+
95
+ Changes to the listened-to directories are reported by the listener thread in a callback.
96
+ The callback receives **three** array parameters: `modified`, `added` and `removed`, in that order.
97
+ Each of these three is always an array with 0 or more entries.
98
+ Each array entry is an absolute path.
99
+
100
+ ### Pause / start / stop
44
101
 
45
- ### "Object" API
102
+ Listeners can also be easily paused and later un-paused with start:
46
103
 
47
104
  ``` ruby
48
- listener = Listen.to('dir/path/to/listen')
49
- listener = listener.ignore(%r{^ignored/path/})
50
- listener = listener.filter(/\.rb$/)
51
- listener = listener.latency(0.5)
52
- listener = listener.force_polling(true)
53
- listener = listener.polling_fallback_message(false)
54
- listener = listener.change(&callback)
55
- listener.start # blocks execution!
105
+ listener = Listen.to('dir/path/to/listen') { |modified, added, removed| puts 'handle changes here...' }
106
+
107
+ listener.start
108
+ listener.paused? # => false
109
+ listener.processing? # => true
110
+
111
+ listener.pause # stops processing changes (but keeps on collecting them)
112
+ listener.paused? # => true
113
+ listener.processing? # => false
114
+
115
+ listener.start # resumes processing changes
116
+ listener.stop # stop both listening to changes and processing them
56
117
  ```
57
118
 
58
- ### Chainable
119
+ Note: While paused, `listen` keeps on collecting changes in the background - to clear them, call `stop`.
120
+
121
+ Note: You should keep track of all started listeners and `stop` them properly on finish.
122
+
123
+ ### Ignore / ignore!
124
+
125
+ `Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
126
+ You can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.
59
127
 
60
128
  ``` ruby
61
- Listen.to('dir/path/to/listen')
62
- .ignore(%r{^ignored/path/})
63
- .filter(/\.rb$/)
64
- .latency(0.5)
65
- .force_polling(true)
66
- .polling_fallback_message('custom message')
67
- .change(&callback)
68
- .start # blocks execution!
129
+ listener = Listen.to('dir/path/to/listen', ignore: /\.txt/) { |modified, added, removed| # ... }
130
+ listener.start
131
+ listener.ignore! /\.pkg/ # overwrite all patterns and only ignore pkg extension.
132
+ listener.ignore /\.rb/ # ignore rb extension in addition of pkg.
133
+ sleep
69
134
  ```
70
135
 
71
- ### Pause/Unpause
136
+ Note: `:ignore` regexp patterns are evaluated against relative paths.
137
+
138
+ Note: Ignoring paths does not improve performance, except when Polling ([#274](https://github.com/guard/listen/issues/274)).
72
139
 
73
- Listener can also easily be paused/unpaused:
140
+ ### Only
141
+
142
+ `Listen` watches all files (less the ignored ones) by default. If you want to only listen to a specific type of file (i.e., just `.rb` extension), you should use the `only` option/method.
74
143
 
75
144
  ``` ruby
76
- listener = Listen.to('dir/path/to/listen')
77
- listener.start(false) # non-blocking mode
78
- listener.pause # stop listening to changes
79
- listener.paused? # => true
80
- listener.unpause
81
- listener.stop
145
+ listener = Listen.to('dir/path/to/listen', only: /\.rb$/) { |modified, added, removed| # ... }
146
+ listener.start
147
+ listener.only /_spec\.rb$/ # overwrite all existing only patterns.
148
+ sleep
82
149
  ```
83
150
 
84
- ## Listening to changes on multiple directories
151
+ Note: `:only` regexp patterns are evaluated only against relative **file** paths.
152
+
85
153
 
86
- The Listen gem provides the `MultiListener` class to watch multiple directories and
87
- handle their changes from a single listener:
154
+ ## Options
155
+
156
+ All the following options can be set through the `Listen.to` after the directory path(s) params.
88
157
 
89
158
  ```ruby
90
- listener = Listen::MultiListener.new('app/css', 'app/js')
91
- listener.latency(0.5)
159
+ ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/] # Ignore a list of paths
160
+ # default: See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
92
161
 
93
- # Configure the listener to your needs...
162
+ ignore!: %r{/foo/bar} # Same as ignore options, but overwrite default ignored paths.
94
163
 
95
- listener.start # blocks execution!
96
- ````
164
+ only: %r{.rb$} # Only listen to specific files
165
+ # default: none
97
166
 
98
- For an easier access, the `Listen.to` method can also be used to create a multi-listener:
167
+ latency: 0.5 # Set the delay (**in seconds**) between checking for changes
168
+ # default: 0.25 sec (1.0 sec for polling)
99
169
 
100
- ``` ruby
101
- listener = Listen.to('app/css', 'app/js')
102
- .ignore(%r{^vendor/}) # both js/vendor and css/vendor will be ignored
103
- .change(&assets_callback)
170
+ wait_for_delay: 4 # Set the delay (**in seconds**) between calls to the callback when changes exist
171
+ # default: 0.10 sec
104
172
 
105
- listener.start # blocks execution!
173
+ force_polling: true # Force the use of the polling adapter
174
+ # default: none
175
+
176
+ relative: false # Whether changes should be relative to current dir or not
177
+ # default: false
178
+
179
+ polling_fallback_message: 'custom message' # Set a custom polling fallback message (or disable it with false)
180
+ # default: "Listen will be polling for changes. Learn more at https://github.com/guard/listen#listen-adapters."
106
181
  ```
107
182
 
108
- ## Changes callback
183
+ ## Logging and Debugging
109
184
 
110
- Changes to the listened-to directories gets reported back to the user in a callback.
111
- The registered callback gets invoked, when there are changes, with **three** parameters:
112
- `modified_paths`, `added_paths` and `removed_paths` in that particular order.
185
+ `Listen` logs its activity to `Listen.logger`.
186
+ This is the primary method of debugging.
113
187
 
114
- You can register a callback in two ways. The first way is by passing a block when calling
115
- the `Listen.to` method or when initializing a listener object:
188
+ ### Custom Logger
189
+ You can call `Listen.logger =` to set a custom `listen` logger for the process. For example:
190
+ ```
191
+ Listen.logger = Rails.logger
192
+ ```
116
193
 
117
- ```ruby
118
- Listen.to('path/to/app') do |modified, added, removed|
119
- # This block will be called when there are changes.
120
- end
194
+ ### Default Logger
195
+ If no custom logger is set, a default `listen` logger which logs to to `STDERR` will be created and assigned to `Listen.logger`.
121
196
 
122
- # or ...
197
+ The default logger defaults to the `error` logging level (severity).
198
+ You can override the logging level by setting the environment variable `LISTEN_GEM_DEBUGGING=<level>`.
199
+ For `<level>`, all standard `::Logger` levels are supported, with any mix of upper-/lower-case:
200
+ ```
201
+ export LISTEN_GEM_DEBUGGING=debug # or 2 [deprecated]
202
+ export LISTEN_GEM_DEBUGGING=info # or 1 or true or yes [deprecated]
203
+ export LISTEN_GEM_DEBUGGING=warn
204
+ export LISTEN_GEM_DEBUGGING=fatal
205
+ export LISTEN_GEM_DEBUGGING=error
206
+ ```
207
+ The default of `error` will be used if an unsupported value is set.
123
208
 
124
- listener = Listen::Listener.new('path/to/app') do |modified, added, removed|
125
- # This block will be called when there are changes.
126
- end
209
+ Note: The alternate values `1`, `2`, `true` and `yes` shown above are deprecated and will be removed from `listen` v4.0.
127
210
 
211
+ ### Disabling Logging
212
+ If you want to disable `listen` logging, set
213
+ ```
214
+ Listen.logger = ::Logger.new('/dev/null')
128
215
  ```
216
+ ## Listen Adapters
129
217
 
130
- The second way to register a callback is be calling the `change` method on any
131
- listener passing it a block:
218
+ The `Listen` gem has a set of adapters to notify it when there are changes.
132
219
 
133
- ```ruby
134
- # Create a callback
135
- callback = Proc.new do |modified, added, removed|
136
- # This proc will be called when there are changes.
137
- end
220
+ There are 4 OS-specific adapters to support Darwin, Linux, \*BSD and Windows.
221
+ These adapters are fast as they use some system-calls to implement the notifying function.
138
222
 
139
- listener = Listen.to('dir')
140
- listener.change(&callback) # convert the callback to a block and register it
223
+ There is also a polling adapter - although it's much slower than other adapters,
224
+ it works on every platform/system and scenario (including network filesystems such as VM shared folders).
141
225
 
142
- listener.start # blocks execution
143
- ```
226
+ The Darwin and Linux adapters are dependencies of the `listen` gem so they work out of the box. For other adapters a specific gem will have to be added to your Gemfile, please read below.
227
+
228
+ The `listen` gem will choose the best adapter automatically, if present. If you
229
+ want to force the use of the polling adapter, use the `:force_polling` option
230
+ while initializing the listener.
231
+
232
+ ### On Windows
144
233
 
145
- ### Paths in callbacks
234
+ If you are on Windows, it's recommended to use the [`wdm`](https://github.com/Maher4Ever/wdm) adapter instead of polling.
146
235
 
147
- Listeners invoke callbacks passing them absolute paths by default:
236
+ Please add the following to your Gemfile:
148
237
 
149
238
  ```ruby
150
- # Assume someone changes the 'style.css' file in '/home/user/app/css' after creating
151
- # the listener.
152
- Listen.to('/home/user/app/css') do |modified, added, removed|
153
- modified.inspect # => ['/home/user/app/css/style.css']
154
- end
239
+ gem 'wdm', '>= 0.1.0', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
155
240
  ```
156
241
 
157
- #### Relative paths in callbacks
242
+ ### On \*BSD
243
+
244
+ If you are on \*BSD you can try to use the [`rb-kqueue`](https://github.com/mat813/rb-kqueue) adapter instead of polling.
158
245
 
159
- When creating a listener for a **single** path (more specifically a `Listen::Listener` instance),
160
- you can pass `:relative_paths => true` as an option to get relative paths in
161
- your callback:
246
+ Please add the following to your Gemfile:
162
247
 
163
248
  ```ruby
164
- # Assume someone changes the 'style.css' file in '/home/user/app/css' after creating
165
- # the listener.
166
- Listen.to('/home/user/app/css', :relative_paths => true) do |modified, added, removed|
167
- modified.inspect # => ['style.css']
249
+ require 'rbconfig'
250
+ if RbConfig::CONFIG['target_os'] =~ /bsd|dragonfly/i
251
+ gem 'rb-kqueue', '>= 0.2'
168
252
  end
253
+
169
254
  ```
170
255
 
171
- Passing the `:relative_paths => true` option won't work when listeneing to multiple
172
- directories:
256
+ ### Getting the [polling fallback message](#options)?
173
257
 
174
- ```ruby
175
- # Assume someone changes the 'style.css' file in '/home/user/app/css' after creating
176
- # the listener.
177
- Listen.to('/home/user/app/css', '/home/user/app/js', :relative_paths => true) do |modified, added, removed|
178
- modified.inspect # => ['/home/user/app/css/style.css']
179
- end
258
+ If you see:
259
+ ```
260
+ Listen will be polling for changes.
180
261
  ```
181
262
 
182
- ## Options
263
+ This means the Listen gem can’t find an optimized adapter. Typically this is caused by:
183
264
 
184
- These options can be set through `Listen.to` params or via methods (see the "Object" API)
265
+ - You’re on Windows and WDM gem isn’t installed.
266
+ - You’re running the app without Bundler or RubyGems.
267
+ - Using Sass which includes an ancient (the “dinosaur” type of ancient) version of the Listen gem.
185
268
 
186
- ```ruby
187
- :filter => /\.rb$/, /\.coffee$/ # Filter files to listen to via a regexps list.
188
- # default: none
269
+ Possible solutions:
189
270
 
190
- :ignore => %r{app/CMake/}, /\.pid$/ # Ignore a list of paths (root directory or sub-dir)
191
- # default: See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::DirectoryRecord
271
+ 1. Suppress the message by using the :force_polling option. Or, you could just ignore the message since it’s harmless.
272
+ 2. Windows users: Install the WDM gem.
273
+ 3. Upgrade Ruby (use RubyInstaller for Windows or RVM/rbenv for Mac) and RubyGems.
274
+ 3. Run your apps using Bundler.
275
+ 4. Sass users: Install the latest version of Listen and try again.
192
276
 
193
- :latency => 0.5 # Set the delay (**in seconds**) between checking for changes
194
- # default: 0.25 sec (1.0 sec for polling)
195
-
196
- :relative_paths => true # Enable the use of relative paths in the callback.
197
- # default: false
277
+ #### Simplified Bundler and Sass example
278
+ Create a Gemfile with these lines:
279
+ ```
280
+ source 'https://rubygems.org'
281
+ gem 'listen'
282
+ gem 'sass'
283
+ ```
284
+ Next, use Bundler to update gems:
285
+ ```
286
+ $ bundle update
287
+ $ bundle exec sass --watch # ... or whatever app is using Listen.
288
+ ```
198
289
 
199
- :force_polling => true # Force the use of the polling adapter
200
- # default: none
290
+ ### Increasing the amount of inotify watchers
201
291
 
202
- :polling_fallback_message => 'custom message' # Set a custom polling fallback message (or disable it with `false`)
203
- # default: "WARNING: Listen fallen back to polling, learn more at https://github.com/guard/listen#fallback."
292
+ If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal:
293
+ ```
294
+ $ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
295
+ $ sudo sysctl -p
296
+ ```
297
+ If you are running ArchLinux, search the `/etc/sysctl.d/` directory for config files with the setting:
298
+ ```
299
+ $ grep -H -s "fs.inotify.max_user_watches" /etc/sysctl.d/*
300
+ /etc/sysctl.d/40-max_user_watches.conf:fs.inotify.max_user_watches=100000
301
+ ```
302
+ 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):
303
+ ```
304
+ $ sudo sh -c "echo fs.inotify.max_user_watches=524288 > /etc/sysctl.d/40-max-user-watches.conf"
305
+ $ sudo sysctl --system
204
306
  ```
205
307
 
206
- ### The patterns for filtering and ignoring paths
308
+ #### The technical details
309
+ Listen uses `inotify` by default on Linux to monitor directories for changes.
310
+ It's not uncommon to encounter a system limit on the number of files you can monitor.
311
+ For example, Ubuntu Lucid's (64bit) `inotify` limit is set to 8192.
207
312
 
208
- Just like the unix convention of beginning absolute paths with the
209
- directory-separator (forward slash `/` in unix) and with no prefix for relative paths,
210
- Listen doesn't prefix relative paths (to the watched directory) with a directory-separator.
313
+ You can get your current inotify file watch limit by executing:
314
+ ```
315
+ $ cat /proc/sys/fs/inotify/max_user_watches
316
+ ```
317
+ When this limit is not enough to monitor all files inside a directory, the limit must be increased for Listen to work properly.
211
318
 
212
- Therefore make sure _NOT_ to prefix your regexp-patterns for filtering or ignoring paths
213
- with a directory-separator, otherwise they won't work as expected.
319
+ You can set a new limit temporarily with:
320
+ ```
321
+ $ sudo sysctl fs.inotify.max_user_watches=524288
322
+ $ sudo sysctl -p
323
+ ```
324
+ If you like to make your limit permanent, use:
325
+ ```
326
+ $ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
327
+ $ sudo sysctl -p
328
+ ```
329
+ You may also need to pay attention to the values of `max_queued_events` and `max_user_instances` if Listen keeps on complaining.
214
330
 
215
- As an example: to ignore the `build` directory in a C-project, use `%r{build/}`
216
- and not `%r{/build/}`.
331
+ #### More info
332
+ Man page for [inotify(7)](https://linux.die.net/man/7/inotify).
333
+ Blog post: [limit of inotify](https://blog.sorah.jp/2012/01/24/inotify-limitation).
217
334
 
218
- ### Non-blocking listening to changes
335
+ ### Issues and Troubleshooting
219
336
 
220
- Starting a listener blocks the current thread by default. That means any code after the
221
- `start` call won't be run until the listener is stopped (which needs to be done from another thread).
337
+ If the gem doesn't work as expected, start by setting `LISTEN_GEM_DEBUGGING=debug` or `LISTEN_GEM_DEBUGGING=info` as described above in [Logging and Debugging](#logging-and-debugging).
222
338
 
223
- For advanced usage there is an option to disable this behavior and have the listener start working
224
- in the background without blocking. To enable non-blocking listening the `start` method of
225
- the listener (be it `Listener` or `MultiListener`) needs to be called with `false` as a parameter.
339
+ *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.*
226
340
 
227
- Here is an example of using a listener in the non-blocking mode:
341
+ #### 3 steps before you start diagnosing problems
342
+ These 3 steps will:
228
343
 
229
- ```ruby
230
- listener = Listen.to('dir/path/to/listen')
231
- listener.start(false) # doesn't block execution
344
+ - help quickly troubleshoot obscure problems (trust me, most of them are obscure)
345
+ - help quickly identify the area of the problem (a full list is below)
346
+ - help you get familiar with listen's diagnostic mode (it really comes in handy, trust me)
347
+ - help you create relevant output before you submit an issue (so we can respond with answers instead of tons of questions)
232
348
 
233
- # Code here will run immediately after starting the listener
349
+ Step 1 - The most important option in Listen
350
+ For effective troubleshooting set the `LISTEN_GEM_DEBUGGING=info` variable before starting `listen`.
234
351
 
235
- ```
352
+ Step 2 - Verify polling works
353
+ Polling has to work ... or something is really wrong (and we need to know that before anything else).
236
354
 
237
- **note**: Using the `Listen.to` helper-method with a callback-block will always
238
- block execution. See the "Block API" section for an example.
355
+ (see force_polling option).
239
356
 
240
- ## Listen adapters
357
+ After starting `listen`, you should see something like:
358
+ ```
359
+ INFO -- : Record.build(): 0.06773114204406738 seconds
360
+ ```
361
+ Step 3 - Trigger some changes directly without using editors or apps
362
+ Make changes e.g. touch foo or echo "a" >> foo (for troubleshooting, avoid using an editor which could generate too many misleading events).
241
363
 
242
- The Listen gem has a set of adapters to notify it when there are changes.
243
- There are 3 OS-specific adapters to support Mac, Linux and Windows. These adapters are fast
244
- as they use some system-calls to implement the notifying function.
364
+ You should see something like:
365
+ ```
366
+ INFO -- : listen: raw changes: [[:added, "/home/me/foo"]]
367
+ INFO -- : listen: final changes: {:modified=>[], :added=>["/home/me/foo"], :removed=>[]}
368
+ ```
369
+ "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).
245
370
 
246
- There is also a polling adapter which is a cross-platform adapter and it will
247
- work on any system. This adapter is unfortunately slower than the rest of the adapters.
371
+ ## Performance
248
372
 
249
- The Listen gem will choose the best and working adapter for your machine automatically. If you
250
- want to force the use of the polling adapter, either use the `:force_polling` option
251
- while initializing the listener or call the `force_polling` method on your listener
252
- before starting it.
373
+ If `listen` seems slow or unresponsive, make sure you're not using the Polling adapter (you should see a warning upon startup if you are).
253
374
 
254
- ## Polling fallback
375
+ Also, if the directories you're watching contain many files, make sure you're:
255
376
 
256
- When a OS-specific adapter doesn't work the Listen gem automatically falls back to the polling adapter.
257
- Here are some things you could try to avoid the polling fallback:
377
+ * not using Polling (ideally)
378
+ * using `:ignore` and `:only` options to avoid tracking directories you don't care about (important with Polling and on MacOS)
379
+ * running `listen` with the `:latency` and `:wait_for_delay` options not too small or too big (depends on needs)
380
+ * not watching directories with log files, database files or other frequently changing files
381
+ * not using a version of `listen` prior to 2.7.7
382
+ * not getting silent crashes within `listen` (see `LISTEN_GEM_DEBUGGING=debug`)
383
+ * not running multiple instances of `listen` in the background
384
+ * using a file system with atime modification disabled (ideally)
385
+ * not using a filesystem with inaccurate file modification times (ideally), e.g. HFS, VFAT
386
+ * not buffering to a slow terminal (e.g. transparency + fancy font + slow gfx card + lots of output)
387
+ * ideally not running a slow encryption stack, e.g. btrfs + ecryptfs
258
388
 
259
- * [Update your Dropbox client](http://www.dropbox.com/downloading) (if used).
260
- * Increase latency. (Please [open an issue](https://github.com/guard/listen/issues/new) if you think that default is too low.)
261
- * Move or rename the listened folder.
262
- * Update/reboot your OS.
389
+ When in doubt, `LISTEN_GEM_DEBUGGING=debug` can help discover the actual events and time they happened.
263
390
 
264
- 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).
391
+ ## Tips and Techniques
392
+ - Watch only directories you're interested in.
393
+ - Set your editor to save quickly (e.g. without backup files, without atomic-save)
394
+ - Tweak the `:latency` and `:wait_for_delay` options until you get good results (see [options](#options)).
395
+ - Add `:ignore` rules to silence all events you don't care about (reduces a lot of noise, especially if you use it on directories)
265
396
 
266
- ## Development [![Dependency Status](https://gemnasium.com/guard/listen.png?branch=master)](https://gemnasium.com/guard/listen)
397
+ ## Development
267
398
 
268
399
  * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/listen/master/frames).
269
400
  * Source hosted at [GitHub](https://github.com/guard/listen).
@@ -271,41 +402,61 @@ If your application keeps using the polling-adapter and you can't figure out why
271
402
  Pull requests are very welcome! Please try to follow these simple rules if applicable:
272
403
 
273
404
  * Please create a topic branch for every separate change you make.
274
- * Make sure your patches are well tested. All specs run with `rake spec:portability` must pass.
405
+ * Make sure your patches are well tested. All specs must pass on [Travis CI](https://travis-ci.org/guard/listen).
275
406
  * Update the [Yard](http://yardoc.org/) documentation.
276
- * Update the README.
277
- * Update the CHANGELOG for noteworthy changes.
407
+ * Update the [README](https://github.com/guard/listen/blob/master/README.md).
278
408
  * Please **do not change** the version number.
279
409
 
280
410
  For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
281
411
  `#guard` (irc.freenode.net).
282
412
 
283
- ## Acknowledgment
413
+ ## Releasing
414
+
415
+ ### Prerequisites
416
+
417
+ * You must have commit rights to the GitHub repository.
418
+ * You must have push rights for rubygems.org.
419
+
420
+ ### How to release
421
+
422
+ 1. Run `bundle install` to make sure that you have all the gems necessary for testing and releasing.
423
+ 2. **Ensure all tests are passing by running `bundle exec rake`.**
424
+ 3. Determine which would be the correct next version number according to [semver](http://semver.org/).
425
+ 4. Update the version in `./lib/listen/version.rb`.
426
+ 5. Update the version in the Install section of `./README.md` (`gem 'listen', '~> X.Y'`).
427
+ 6. Commit the version in a single commit, the message should be "Preparing vX.Y.Z"
428
+ 7. Run `bundle exec rake release:full`; this will tag, push to GitHub, and publish to rubygems.org.
429
+ 8. Update and publish the release notes on the [GitHub releases page](https://github.com/guard/listen/releases) if necessary
430
+
431
+ ## Acknowledgments
284
432
 
285
433
  * [Michael Kessler (netzpirat)][] for having written the [initial specs](https://github.com/guard/listen/commit/1e457b13b1bb8a25d2240428ce5ed488bafbed1f).
286
434
  * [Travis Tilley (ttilley)][] for this awesome work on [fssm][] & [rb-fsevent][].
287
- * [Nathan Weizenbaum (nex3)][] for [rb-inotify][], a thorough inotify wrapper.
288
- * [stereobooster][] for [rb-fchange][], windows support wouldn't exist without him.
435
+ * [Natalie Weizenbaum (nex3)][] for [rb-inotify][], a thorough inotify wrapper.
436
+ * [Mathieu Arnold (mat813)][] for [rb-kqueue][], a simple kqueue wrapper.
437
+ * [Maher Sallam][] for [wdm][], windows support wouldn't exist without him.
289
438
  * [Yehuda Katz (wycats)][] for [vigilo][], that has been a great source of inspiration.
290
439
 
291
- ## Authors
440
+ ## Author
292
441
 
293
- * [Thibaud Guillaume-Gentil][] ([@thibaudgg](http://twitter.com/thibaudgg))
294
- * [Maher Sallam][] ([@mahersalam](http://twitter.com/mahersalam))
442
+ [Thibaud Guillaume-Gentil](https://github.com/thibaudgg) ([@thibaudgg](https://twitter.com/thibaudgg))
295
443
 
296
444
  ## Contributors
297
445
 
298
- [https://github.com/guard/listen/contributors](https://github.com/guard/listen/contributors)
446
+ [https://github.com/guard/listen/graphs/contributors](https://github.com/guard/listen/graphs/contributors)
299
447
 
300
- [Thibaud Guillaume-Gentil]: https://github.com/thibaudgg
448
+ [Thibaud Guillaume-Gentil (thibaudgg)]: https://github.com/thibaudgg
301
449
  [Maher Sallam]: https://github.com/Maher4Ever
302
450
  [Michael Kessler (netzpirat)]: https://github.com/netzpirat
303
451
  [Travis Tilley (ttilley)]: https://github.com/ttilley
304
452
  [fssm]: https://github.com/ttilley/fssm
305
453
  [rb-fsevent]: https://github.com/thibaudgg/rb-fsevent
306
- [Nathan Weizenbaum (nex3)]: https://github.com/nex3
454
+ [Mathieu Arnold (mat813)]: https://github.com/mat813
455
+ [Natalie Weizenbaum (nex3)]: https://github.com/nex3
307
456
  [rb-inotify]: https://github.com/nex3/rb-inotify
308
457
  [stereobooster]: https://github.com/stereobooster
309
458
  [rb-fchange]: https://github.com/stereobooster/rb-fchange
459
+ [rb-kqueue]: https://github.com/mat813/rb-kqueue
310
460
  [Yehuda Katz (wycats)]: https://github.com/wycats
311
461
  [vigilo]: https://github.com/wycats/vigilo
462
+ [wdm]: https://github.com/Maher4Ever/wdm