listen 3.3.0 → 3.9.0
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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +2 -2
- data/README.md +156 -24
- data/bin/listen +3 -4
- data/lib/listen/adapter/base.rb +7 -7
- data/lib/listen/adapter/bsd.rb +4 -5
- data/lib/listen/adapter/config.rb +7 -4
- data/lib/listen/adapter/darwin.rb +3 -3
- data/lib/listen/adapter/linux.rb +8 -9
- data/lib/listen/adapter/polling.rb +6 -5
- data/lib/listen/adapter/windows.rb +11 -15
- data/lib/listen/adapter.rb +4 -4
- data/lib/listen/change.rb +10 -19
- data/lib/listen/cli.rb +5 -6
- data/lib/listen/directory.rb +6 -8
- data/lib/listen/error.rb +11 -0
- data/lib/listen/event/config.rb +4 -9
- data/lib/listen/event/loop.rb +6 -8
- data/lib/listen/event/processor.rb +13 -15
- data/lib/listen/event/queue.rb +9 -9
- data/lib/listen/file.rb +13 -5
- data/lib/listen/fsm.rb +5 -2
- data/lib/listen/listener/config.rb +2 -4
- data/lib/listen/listener.rb +2 -0
- data/lib/listen/logger.rb +42 -12
- data/lib/listen/monotonic_time.rb +27 -0
- data/lib/listen/options.rb +9 -8
- data/lib/listen/queue_optimizer.rb +7 -12
- data/lib/listen/record/entry.rb +1 -1
- data/lib/listen/record/symlink_detector.rb +14 -8
- data/lib/listen/record.rb +37 -46
- data/lib/listen/silencer.rb +24 -20
- data/lib/listen/thread.rb +14 -12
- data/lib/listen/version.rb +1 -1
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b365e353c2a0dc2a64459faa2c30a9b472130637b5fb4f50977c07adb2c6fd0c
|
4
|
+
data.tar.gz: 82d72d4f26f25a7fd1e285fbebe66fffcee246999696313a4f19997ce2017ef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f52228164dce447a048dea3e04268909004e17f0b40788495f58f9afc9a9a9f3a0207fd0acb541d0cffe0be78836a10f652acf6ff418cea9ea119708eaec0b83
|
7
|
+
data.tar.gz: ee91854777075dc80f4cbcff3e507f4ca162aabe37fa11709b145184ada246efd0401ba89a50de8008c2ca7345d0dd08d20bbad7c6d9272004ad3581e74abca5
|
data/CONTRIBUTING.md
CHANGED
@@ -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/
|
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/
|
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
|
[](https://github.com/guard/listen/actions?workflow=Development)
|
8
6
|
[](http://badge.fury.io/rb/listen)
|
9
7
|
[](https://codeclimate.com/github/guard/listen)
|
@@ -16,21 +14,19 @@ The `listen` gem listens to file modifications and notifies you about the change
|
|
16
14
|
* You can watch multiple directories.
|
17
15
|
* Regexp-patterns for ignoring paths for more accuracy and speed
|
18
16
|
* Increased change detection accuracy on OS X HFS and VFAT volumes.
|
19
|
-
* Continuous Integration: tested on selected Ruby environments via [Github Workflows](https
|
17
|
+
* Continuous Integration: tested on selected Ruby environments via [Github Workflows](https://github.com/guard/listen/tree/master/.github/workflows).
|
20
18
|
|
21
19
|
## Issues / limitations
|
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)
|
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'`.
|
29
27
|
* Some filesystems won't work without polling (VM/Vagrant Shared folders, NFS, Samba, sshfs, etc.).
|
30
|
-
* Specs suite on JRuby and Rubinius aren't reliable on Travis CI, but should work.
|
31
28
|
* Windows and \*BSD adapter aren't continuously and automatically tested.
|
32
29
|
* OSX adapter has some performance limitations ([#342](https://github.com/guard/listen/issues/342)).
|
33
|
-
* FreeBSD users need patched version of rb-kqueue (as of 2020/11). See #475 for the issue, mat813/rb-kqueue#12 for the patch, and Bug 250432 in bugzilla.
|
34
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).
|
35
31
|
|
36
32
|
Pull requests or help is very welcome for these.
|
@@ -40,7 +36,7 @@ Pull requests or help is very welcome for these.
|
|
40
36
|
The simplest way to install `listen` is to use [Bundler](http://bundler.io).
|
41
37
|
|
42
38
|
```ruby
|
43
|
-
gem 'listen'
|
39
|
+
gem 'listen'
|
44
40
|
```
|
45
41
|
|
46
42
|
## Complete Example
|
@@ -101,23 +97,23 @@ The callback receives **three** array parameters: `modified`, `added` and `remov
|
|
101
97
|
Each of these three is always an array with 0 or more entries.
|
102
98
|
Each array entry is an absolute path.
|
103
99
|
|
104
|
-
### Pause /
|
100
|
+
### Pause / start / stop
|
105
101
|
|
106
|
-
Listeners can also be easily paused
|
102
|
+
Listeners can also be easily paused and later un-paused with start:
|
107
103
|
|
108
104
|
``` ruby
|
109
105
|
listener = Listen.to('dir/path/to/listen') { |modified, added, removed| puts 'handle changes here...' }
|
110
106
|
|
111
107
|
listener.start
|
112
|
-
listener.paused?
|
108
|
+
listener.paused? # => false
|
113
109
|
listener.processing? # => true
|
114
110
|
|
115
|
-
listener.pause
|
116
|
-
listener.paused?
|
111
|
+
listener.pause # stops processing changes (but keeps on collecting them)
|
112
|
+
listener.paused? # => true
|
117
113
|
listener.processing? # => false
|
118
114
|
|
119
|
-
listener.
|
120
|
-
listener.stop
|
115
|
+
listener.start # resumes processing changes
|
116
|
+
listener.stop # stop both listening to changes and processing them
|
121
117
|
```
|
122
118
|
|
123
119
|
Note: While paused, `listen` keeps on collecting changes in the background - to clear them, call `stop`.
|
@@ -126,7 +122,7 @@ listener.stop # stop both listening to changes and processing them
|
|
126
122
|
|
127
123
|
### Ignore / ignore!
|
128
124
|
|
129
|
-
`Listen` ignores some directories and extensions by default (See
|
125
|
+
`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
|
130
126
|
You can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.
|
131
127
|
|
132
128
|
``` ruby
|
@@ -159,9 +155,9 @@ Note: `:only` regexp patterns are evaluated only against relative **file** paths
|
|
159
155
|
|
160
156
|
All the following options can be set through the `Listen.to` after the directory path(s) params.
|
161
157
|
|
162
|
-
```ruby
|
158
|
+
``` ruby
|
163
159
|
ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/] # Ignore a list of paths
|
164
|
-
# default: See
|
160
|
+
# default: See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
|
165
161
|
|
166
162
|
ignore!: %r{/foo/bar} # Same as ignore options, but overwrite default ignored paths.
|
167
163
|
|
@@ -191,7 +187,7 @@ This is the primary method of debugging.
|
|
191
187
|
|
192
188
|
### Custom Logger
|
193
189
|
You can call `Listen.logger =` to set a custom `listen` logger for the process. For example:
|
194
|
-
```
|
190
|
+
``` ruby
|
195
191
|
Listen.logger = Rails.logger
|
196
192
|
```
|
197
193
|
|
@@ -201,7 +197,7 @@ If no custom logger is set, a default `listen` logger which logs to to `STDERR`
|
|
201
197
|
The default logger defaults to the `error` logging level (severity).
|
202
198
|
You can override the logging level by setting the environment variable `LISTEN_GEM_DEBUGGING=<level>`.
|
203
199
|
For `<level>`, all standard `::Logger` levels are supported, with any mix of upper-/lower-case:
|
204
|
-
```
|
200
|
+
``` ruby
|
205
201
|
export LISTEN_GEM_DEBUGGING=debug # or 2 [deprecated]
|
206
202
|
export LISTEN_GEM_DEBUGGING=info # or 1 or true or yes [deprecated]
|
207
203
|
export LISTEN_GEM_DEBUGGING=warn
|
@@ -214,9 +210,38 @@ Note: The alternate values `1`, `2`, `true` and `yes` shown above are deprecated
|
|
214
210
|
|
215
211
|
### Disabling Logging
|
216
212
|
If you want to disable `listen` logging, set
|
217
|
-
```
|
213
|
+
``` ruby
|
218
214
|
Listen.logger = ::Logger.new('/dev/null')
|
219
215
|
```
|
216
|
+
|
217
|
+
### Adapter Warnings
|
218
|
+
If listen is having trouble with the underlying adapter, it will display warnings with `Kernel#warn` by default,
|
219
|
+
which in turn writes to STDERR.
|
220
|
+
Sometimes this is not desirable, for example in an environment where STDERR is ignored.
|
221
|
+
For these reasons, the behavior can be configured using `Listen.adapter_warn_behavior =`:
|
222
|
+
``` ruby
|
223
|
+
Listen.adapter_warn_behavior = :warn # default (true means the same)
|
224
|
+
Listen.adapter_warn_behavior = :log # send to logger.warn
|
225
|
+
Listen.adapter_warn_behavior = :silent # suppress all adapter warnings (nil or false mean the same)
|
226
|
+
```
|
227
|
+
Also there are some cases where specific warnings are not helpful.
|
228
|
+
For example, if you are using the polling adapter--and expect to--you can suppress the warning about it
|
229
|
+
by providing a callable object like a lambda or proc that determines the behavior based on the `message`:
|
230
|
+
``` ruby
|
231
|
+
Listen.adapter_warn_behavior = ->(message) do
|
232
|
+
case message
|
233
|
+
when /Listen will be polling for changes/
|
234
|
+
:silent
|
235
|
+
when /directory is already being watched/
|
236
|
+
:log
|
237
|
+
else
|
238
|
+
:warn
|
239
|
+
end
|
240
|
+
end
|
241
|
+
```
|
242
|
+
In cases where the `Listen` gem is embedded inside another service--such as `guard`--the above configuration
|
243
|
+
can be set in the environment variable `LISTEN_GEM_ADAPTER_WARN_BEHAVIOR=warn|log|silent`.
|
244
|
+
|
220
245
|
## Listen Adapters
|
221
246
|
|
222
247
|
The `Listen` gem has a set of adapters to notify it when there are changes.
|
@@ -240,7 +265,7 @@ If you are on Windows, it's recommended to use the [`wdm`](https://github.com/Ma
|
|
240
265
|
Please add the following to your Gemfile:
|
241
266
|
|
242
267
|
```ruby
|
243
|
-
gem 'wdm', '>= 0.1.0'
|
268
|
+
gem 'wdm', '>= 0.1.0', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
244
269
|
```
|
245
270
|
|
246
271
|
### On \*BSD
|
@@ -259,7 +284,82 @@ end
|
|
259
284
|
|
260
285
|
### Getting the [polling fallback message](#options)?
|
261
286
|
|
262
|
-
|
287
|
+
If you see:
|
288
|
+
```
|
289
|
+
Listen will be polling for changes.
|
290
|
+
```
|
291
|
+
|
292
|
+
This means the Listen gem can’t find an optimized adapter. Typically this is caused by:
|
293
|
+
|
294
|
+
- You’re on Windows and WDM gem isn’t installed.
|
295
|
+
- You’re running the app without Bundler or RubyGems.
|
296
|
+
- Using Sass which includes an ancient (the “dinosaur” type of ancient) version of the Listen gem.
|
297
|
+
|
298
|
+
Possible solutions:
|
299
|
+
|
300
|
+
1. Suppress the message by using the :force_polling option. Or, you could just ignore the message since it’s harmless.
|
301
|
+
2. Windows users: Install the WDM gem.
|
302
|
+
3. Upgrade Ruby (use RubyInstaller for Windows or RVM/rbenv for Mac) and RubyGems.
|
303
|
+
3. Run your apps using Bundler.
|
304
|
+
4. Sass users: Install the latest version of Listen and try again.
|
305
|
+
|
306
|
+
#### Simplified Bundler and Sass example
|
307
|
+
Create a Gemfile with these lines:
|
308
|
+
```
|
309
|
+
source 'https://rubygems.org'
|
310
|
+
gem 'listen'
|
311
|
+
gem 'sass'
|
312
|
+
```
|
313
|
+
Next, use Bundler to update gems:
|
314
|
+
```
|
315
|
+
$ bundle update
|
316
|
+
$ bundle exec sass --watch # ... or whatever app is using Listen.
|
317
|
+
```
|
318
|
+
|
319
|
+
### Increasing the amount of inotify watchers
|
320
|
+
|
321
|
+
If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal:
|
322
|
+
```
|
323
|
+
$ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
|
324
|
+
$ sudo sysctl -p
|
325
|
+
```
|
326
|
+
If you are running ArchLinux, search the `/etc/sysctl.d/` directory for config files with the setting:
|
327
|
+
```
|
328
|
+
$ grep -H -s "fs.inotify.max_user_watches" /etc/sysctl.d/*
|
329
|
+
/etc/sysctl.d/40-max_user_watches.conf:fs.inotify.max_user_watches=100000
|
330
|
+
```
|
331
|
+
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):
|
332
|
+
```
|
333
|
+
$ sudo sh -c "echo fs.inotify.max_user_watches=524288 > /etc/sysctl.d/40-max-user-watches.conf"
|
334
|
+
$ sudo sysctl --system
|
335
|
+
```
|
336
|
+
|
337
|
+
#### The technical details
|
338
|
+
Listen uses `inotify` by default on Linux to monitor directories for changes.
|
339
|
+
It's not uncommon to encounter a system limit on the number of files you can monitor.
|
340
|
+
For example, Ubuntu Lucid's (64bit) `inotify` limit is set to 8192.
|
341
|
+
|
342
|
+
You can get your current inotify file watch limit by executing:
|
343
|
+
```
|
344
|
+
$ cat /proc/sys/fs/inotify/max_user_watches
|
345
|
+
```
|
346
|
+
When this limit is not enough to monitor all files inside a directory, the limit must be increased for Listen to work properly.
|
347
|
+
|
348
|
+
You can set a new limit temporarily with:
|
349
|
+
```
|
350
|
+
$ sudo sysctl fs.inotify.max_user_watches=524288
|
351
|
+
$ sudo sysctl -p
|
352
|
+
```
|
353
|
+
If you like to make your limit permanent, use:
|
354
|
+
```
|
355
|
+
$ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
|
356
|
+
$ sudo sysctl -p
|
357
|
+
```
|
358
|
+
You may also need to pay attention to the values of `max_queued_events` and `max_user_instances` if Listen keeps on complaining.
|
359
|
+
|
360
|
+
#### More info
|
361
|
+
Man page for [inotify(7)](https://linux.die.net/man/7/inotify).
|
362
|
+
Blog post: [limit of inotify](https://blog.sorah.jp/2012/01/24/inotify-limitation).
|
263
363
|
|
264
364
|
### Issues and Troubleshooting
|
265
365
|
|
@@ -267,7 +367,35 @@ If the gem doesn't work as expected, start by setting `LISTEN_GEM_DEBUGGING=debu
|
|
267
367
|
|
268
368
|
*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
369
|
|
270
|
-
|
370
|
+
#### 3 steps before you start diagnosing problems
|
371
|
+
These 3 steps will:
|
372
|
+
|
373
|
+
- help quickly troubleshoot obscure problems (trust me, most of them are obscure)
|
374
|
+
- help quickly identify the area of the problem (a full list is below)
|
375
|
+
- help you get familiar with listen's diagnostic mode (it really comes in handy, trust me)
|
376
|
+
- help you create relevant output before you submit an issue (so we can respond with answers instead of tons of questions)
|
377
|
+
|
378
|
+
Step 1 - The most important option in Listen
|
379
|
+
For effective troubleshooting set the `LISTEN_GEM_DEBUGGING=info` variable before starting `listen`.
|
380
|
+
|
381
|
+
Step 2 - Verify polling works
|
382
|
+
Polling has to work ... or something is really wrong (and we need to know that before anything else).
|
383
|
+
|
384
|
+
(see force_polling option).
|
385
|
+
|
386
|
+
After starting `listen`, you should see something like:
|
387
|
+
```
|
388
|
+
INFO -- : Record.build(): 0.06773114204406738 seconds
|
389
|
+
```
|
390
|
+
Step 3 - Trigger some changes directly without using editors or apps
|
391
|
+
Make changes e.g. touch foo or echo "a" >> foo (for troubleshooting, avoid using an editor which could generate too many misleading events).
|
392
|
+
|
393
|
+
You should see something like:
|
394
|
+
```
|
395
|
+
INFO -- : listen: raw changes: [[:added, "/home/me/foo"]]
|
396
|
+
INFO -- : listen: final changes: {:modified=>[], :added=>["/home/me/foo"], :removed=>[]}
|
397
|
+
```
|
398
|
+
"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
399
|
|
272
400
|
## Performance
|
273
401
|
|
@@ -289,7 +417,11 @@ Also, if the directories you're watching contain many files, make sure you're:
|
|
289
417
|
|
290
418
|
When in doubt, `LISTEN_GEM_DEBUGGING=debug` can help discover the actual events and time they happened.
|
291
419
|
|
292
|
-
|
420
|
+
## Tips and Techniques
|
421
|
+
- Watch only directories you're interested in.
|
422
|
+
- Set your editor to save quickly (e.g. without backup files, without atomic-save)
|
423
|
+
- Tweak the `:latency` and `:wait_for_delay` options until you get good results (see [options](#options)).
|
424
|
+
- 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
425
|
|
294
426
|
## Development
|
295
427
|
|
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
|
-
|
7
|
-
|
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
|
data/lib/listen/adapter/base.rb
CHANGED
@@ -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!')
|
@@ -52,11 +51,12 @@ module Listen
|
|
52
51
|
# TODO: separate config per directory (some day maybe)
|
53
52
|
change_config = Change::Config.new(config.queue, config.silencer)
|
54
53
|
config.directories.each do |dir|
|
55
|
-
record = Record.new(dir)
|
54
|
+
record = Record.new(dir, config.silencer)
|
56
55
|
snapshot = Change.new(change_config, record)
|
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.
|
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 =
|
96
|
+
start = MonotonicTime.now
|
97
97
|
yield
|
98
|
-
diff =
|
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}"
|
data/lib/listen/adapter/bsd.rb
CHANGED
@@ -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: [
|
@@ -34,7 +34,7 @@ module Listen
|
|
34
34
|
require 'find'
|
35
35
|
true
|
36
36
|
rescue LoadError
|
37
|
-
|
37
|
+
Listen.adapter_warn(BUNDLER_DECLARE_GEM)
|
38
38
|
false
|
39
39
|
end
|
40
40
|
|
@@ -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.
|
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
|
@@ -19,6 +16,12 @@ module Listen
|
|
19
16
|
Pathname.new(directory.to_s).realpath
|
20
17
|
end
|
21
18
|
|
19
|
+
@directories.each do |pathname|
|
20
|
+
unless pathname.directory?
|
21
|
+
fail ArgumentError, "must be a directory: #{pathname}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
22
25
|
@silencer = silencer
|
23
26
|
@queue = queue
|
24
27
|
@adapter_options = adapter_options
|
@@ -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
|
@@ -30,7 +30,7 @@ module Listen
|
|
30
30
|
require 'rb-fsevent'
|
31
31
|
fsevent_version = Gem::Version.new(FSEvent::VERSION)
|
32
32
|
return true if fsevent_version <= Gem::Version.new('0.9.4')
|
33
|
-
|
33
|
+
Listen.adapter_warn(INCOMPATIBLE_GEM_VERSION)
|
34
34
|
false
|
35
35
|
end
|
36
36
|
|
@@ -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)
|
data/lib/listen/adapter/linux.rb
CHANGED
@@ -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,26 +21,24 @@ module Listen
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
|
25
|
-
'/
|
26
|
-
|
27
|
-
INOTIFY_LIMIT_MESSAGE = <<-EOS.gsub(/^\s*/, '')
|
28
|
-
FATAL: Listen error: unable to monitor directories for changes.
|
29
|
-
Visit #{WIKI_URL} for info on how to fix this.
|
30
|
-
EOS
|
24
|
+
README_URL = 'https://github.com/guard/listen'\
|
25
|
+
'/blob/master/README.md#increasing-the-amount-of-inotify-watchers'
|
31
26
|
|
32
27
|
def _configure(directory, &callback)
|
33
28
|
require 'rb-inotify'
|
34
29
|
@worker ||= ::INotify::Notifier.new
|
35
30
|
@worker.watch(directory.to_s, *options.events, &callback)
|
36
31
|
rescue Errno::ENOSPC
|
37
|
-
|
32
|
+
raise ::Listen::Error::INotifyMaxWatchesExceeded, <<~EOS
|
33
|
+
Unable to monitor directories for changes because iNotify max watches exceeded. See #{README_URL} .
|
34
|
+
EOS
|
38
35
|
end
|
39
36
|
|
40
37
|
def _run
|
41
38
|
@worker.run
|
42
39
|
end
|
43
40
|
|
41
|
+
# rubocop:disable Metrics/MethodLength
|
44
42
|
def _process_event(dir, event)
|
45
43
|
# NOTE: avoid using event.absolute_name since new API
|
46
44
|
# will need to have a custom recursion implemented
|
@@ -73,6 +71,7 @@ module Listen
|
|
73
71
|
|
74
72
|
_queue_change(:file, dir, rel_path, params)
|
75
73
|
end
|
74
|
+
# rubocop:enable Metrics/MethodLength
|
76
75
|
|
77
76
|
def _skip_event?(event)
|
78
77
|
# 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 =
|
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 =
|
24
|
+
start = MonotonicTime.now
|
25
25
|
@polling_callbacks.each do |callback|
|
26
26
|
callback.call(nil)
|
27
|
-
nap_time = options.latency - (
|
28
|
-
|
29
|
-
|
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,9 +18,9 @@ module Listen
|
|
18
18
|
true
|
19
19
|
rescue LoadError
|
20
20
|
Listen.logger.debug format('wdm - load failed: %s:%s', $ERROR_INFO,
|
21
|
-
|
21
|
+
$ERROR_POSITION * "\n")
|
22
22
|
|
23
|
-
|
23
|
+
Listen.adapter_warn(BUNDLER_DECLARE_GEM)
|
24
24
|
false
|
25
25
|
end
|
26
26
|
|
@@ -38,8 +38,7 @@ module Listen
|
|
38
38
|
yield([:dir, change])
|
39
39
|
end
|
40
40
|
|
41
|
-
|
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
|
-
|
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
|
-
|
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] }.
|
94
|
-
|
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
|
data/lib/listen/adapter.rb
CHANGED
@@ -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.'
|
14
|
+
'Learn more at https://github.com/guard/listen#listen-adapters.'
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def select(options = {})
|
@@ -24,19 +24,19 @@ module Listen
|
|
24
24
|
Polling
|
25
25
|
rescue
|
26
26
|
Listen.logger.warn format('Adapter: failed: %s:%s', $ERROR_POSITION.inspect,
|
27
|
-
|
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.
|
34
|
+
OPTIMIZED_ADAPTERS.find(&:usable?)
|
35
35
|
end
|
36
36
|
|
37
37
|
def _warn_polling_fallback(options)
|
38
38
|
msg = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE)
|
39
|
-
|
39
|
+
Listen.adapter_warn("[Listen warning]:\n #{msg}") if msg
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|