listen 3.0.8 → 3.5.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.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +10 -3
- data/README.md +241 -70
- data/bin/listen +3 -4
- data/lib/listen/adapter/base.rb +25 -33
- data/lib/listen/adapter/bsd.rb +9 -8
- data/lib/listen/adapter/config.rb +4 -5
- data/lib/listen/adapter/darwin.rb +35 -46
- data/lib/listen/adapter/linux.rb +16 -13
- data/lib/listen/adapter/polling.rb +9 -6
- data/lib/listen/adapter/windows.rb +19 -22
- data/lib/listen/adapter.rb +25 -25
- data/lib/listen/backend.rb +7 -10
- data/lib/listen/change.rb +18 -27
- data/lib/listen/cli.rb +6 -6
- data/lib/listen/directory.rb +14 -8
- data/lib/listen/error.rb +10 -0
- data/lib/listen/event/config.rb +9 -28
- data/lib/listen/event/loop.rb +44 -67
- data/lib/listen/event/processor.rb +41 -37
- data/lib/listen/event/queue.rb +14 -18
- data/lib/listen/file.rb +16 -3
- data/lib/listen/fsm.rb +74 -72
- data/lib/listen/listener/config.rb +5 -9
- data/lib/listen/listener.rb +26 -22
- data/lib/listen/logger.rb +24 -20
- data/lib/listen/monotonic_time.rb +27 -0
- data/lib/listen/options.rb +11 -8
- data/lib/listen/queue_optimizer.rb +15 -18
- data/lib/listen/record/entry.rb +8 -4
- data/lib/listen/record/symlink_detector.rb +9 -7
- data/lib/listen/record.rb +30 -33
- data/lib/listen/silencer/controller.rb +2 -0
- data/lib/listen/silencer.rb +16 -9
- data/lib/listen/thread.rb +54 -0
- data/lib/listen/version.rb +3 -1
- data/lib/listen.rb +14 -22
- metadata +20 -28
- data/lib/listen/internals/thread_pool.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 321b55dd88acb041f6dfa31d44047d4f90ebfa970adb85d82facd5ceff94db90
|
4
|
+
data.tar.gz: 4e4eb8728548f782d6b99b7b9b40473102f31315e27dae2bacf2b146c2609969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 843e2fe248d9216087fc09e8a5e70f6ee10ed27e55fe993939c93ee1260d55fa3076a684579cae143f304e24b5ecc98318de0e00678e63bee9f52192b1e7292b
|
7
|
+
data.tar.gz: a74621cffdb908165c010b50848e07e9eef9eed9e53b3449533752f2a54caceb5d57c9e1e02c43560a3e6832d6210fd3540e838de34c6f6d1e391d496a5bf8de
|
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
|
@@ -31,8 +31,15 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
|
|
31
31
|
* Make sure your patches are well tested. All specs run with `rake spec` must pass.
|
32
32
|
* Update the [Yard](http://yardoc.org/) documentation.
|
33
33
|
* Update the [README](https://github.com/guard/listen/blob/master/README.md).
|
34
|
-
* Update the [CHANGELOG](https://github.com/guard/listen/blob/master/CHANGELOG.md) for noteworthy changes.
|
35
34
|
* Please **do not change** the version number.
|
36
35
|
|
36
|
+
The title of your PR will automatically be included in the release notes for the next version of the gem. A maintainer can add one of the following GitHub labels to the PR to automatically categorize it when the release notes are generated:
|
37
|
+
|
38
|
+
- ⚠️ Breaking
|
39
|
+
- ✨ Feature
|
40
|
+
- 🐛 Bug Fix
|
41
|
+
- 📚 Docs
|
42
|
+
- 🏠 Housekeeping
|
43
|
+
|
37
44
|
For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
|
38
45
|
`#guard` (irc.freenode.net).
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
: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.
|
2
|
-
|
3
1
|
# Listen
|
4
2
|
|
5
|
-
|
3
|
+
The `listen` gem listens to file modifications and notifies you about the changes.
|
6
4
|
|
7
|
-
|
5
|
+
[](https://github.com/guard/listen/actions?workflow=Development)
|
6
|
+
[](http://badge.fury.io/rb/listen)
|
7
|
+
[](https://codeclimate.com/github/guard/listen)
|
8
|
+
[](https://coveralls.io/r/guard/listen)
|
8
9
|
|
9
10
|
## Features
|
10
11
|
|
@@ -13,45 +14,90 @@ The Listen gem listens to file modifications and notifies you about the changes.
|
|
13
14
|
* You can watch multiple directories.
|
14
15
|
* Regexp-patterns for ignoring paths for more accuracy and speed
|
15
16
|
* Increased change detection accuracy on OS X HFS and VFAT volumes.
|
16
|
-
*
|
17
|
+
* Continuous Integration: tested on selected Ruby environments via [Github Workflows](https:///github.com/guard/listen/master/.github/workflows).
|
17
18
|
|
18
19
|
## Issues / limitations
|
19
20
|
|
20
21
|
* Limited support for symlinked directories ([#279](https://github.com/guard/listen/issues/279)):
|
21
22
|
* Symlinks are always followed ([#25](https://github.com/guard/listen/issues/25)).
|
22
|
-
* 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).
|
23
24
|
* No directory/adapter-specific configuration options.
|
24
25
|
* Support for plugins planned for future.
|
25
|
-
* TCP functionality was removed in
|
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'`.
|
26
27
|
* Some filesystems won't work without polling (VM/Vagrant Shared folders, NFS, Samba, sshfs, etc.).
|
27
28
|
* Specs suite on JRuby and Rubinius aren't reliable on Travis CI, but should work.
|
28
29
|
* Windows and \*BSD adapter aren't continuously and automatically tested.
|
29
30
|
* OSX adapter has some performance limitations ([#342](https://github.com/guard/listen/issues/342)).
|
30
|
-
*
|
31
|
+
* 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.
|
32
|
+
* 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
33
|
|
32
34
|
Pull requests or help is very welcome for these.
|
33
35
|
|
34
36
|
## Install
|
35
37
|
|
36
|
-
The simplest way to install
|
38
|
+
The simplest way to install `listen` is to use [Bundler](http://bundler.io).
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
gem 'listen'
|
42
|
+
```
|
37
43
|
|
44
|
+
## Complete Example
|
45
|
+
Here is a complete example of using the `listen` gem:
|
38
46
|
```ruby
|
39
|
-
|
47
|
+
require 'listen'
|
48
|
+
|
49
|
+
listener = Listen.to('/srv/app') do |modified, added, removed|
|
50
|
+
puts(modified: modified, added: added, removed: removed)
|
51
|
+
end
|
52
|
+
listener.start
|
53
|
+
sleep
|
54
|
+
```
|
55
|
+
Running the above in the background, you can see the callback block being called in response to each command:
|
56
|
+
```
|
57
|
+
$ cd /srv/app
|
58
|
+
$ touch a.txt
|
59
|
+
{:modified=>[], :added=>["/srv/app/a.txt"], :removed=>[]}
|
60
|
+
|
61
|
+
$ echo more >> a.txt
|
62
|
+
{:modified=>["/srv/app/a.txt"], :added=>[], :removed=>[]}
|
63
|
+
|
64
|
+
$ mv a.txt b.txt
|
65
|
+
{:modified=>[], :added=>["/srv/app/b.txt"], :removed=>["/srv/app/a.txt"]}
|
66
|
+
|
67
|
+
$ vi b.txt
|
68
|
+
# add a line to this new file and press ZZ to save and exit
|
69
|
+
{:modified=>["/srv/app/b.txt"], :added=>[], :removed=>[]}
|
70
|
+
|
71
|
+
$ vi c.txt
|
72
|
+
# add a line and press ZZ to save and exit
|
73
|
+
{:modified=>[], :added=>["/srv/app/c.txt"], :removed=>[]}
|
74
|
+
|
75
|
+
$ rm b.txt c.txt
|
76
|
+
{:modified=>[], :added=>[], :removed=>["/srv/app/b.txt", "/srv/app/c.txt"]}
|
40
77
|
```
|
41
78
|
|
42
79
|
## Usage
|
43
80
|
|
44
|
-
Call `Listen.to` with
|
81
|
+
Call `Listen.to` with one or more directories and the "changes" callback passed as a block.
|
45
82
|
|
46
83
|
``` ruby
|
47
84
|
listener = Listen.to('dir/to/listen', 'dir/to/listen2') do |modified, added, removed|
|
48
|
-
puts "modified absolute path: #{modified}"
|
49
|
-
puts "added absolute path: #{added}"
|
50
|
-
puts "removed absolute path: #{removed}"
|
85
|
+
puts "modified absolute path array: #{modified}"
|
86
|
+
puts "added absolute path array: #{added}"
|
87
|
+
puts "removed absolute path array: #{removed}"
|
51
88
|
end
|
52
|
-
listener.start # not
|
89
|
+
listener.start # starts a listener thread--does not block
|
90
|
+
|
91
|
+
# do whatever you want here...just don't exit the process :)
|
92
|
+
|
53
93
|
sleep
|
54
94
|
```
|
95
|
+
## Changes Callback
|
96
|
+
|
97
|
+
Changes to the listened-to directories are reported by the listener thread in a callback.
|
98
|
+
The callback receives **three** array parameters: `modified`, `added` and `removed`, in that order.
|
99
|
+
Each of these three is always an array with 0 or more entries.
|
100
|
+
Each array entry is an absolute path.
|
55
101
|
|
56
102
|
### Pause / unpause / stop
|
57
103
|
|
@@ -72,13 +118,14 @@ listener.unpause # resumes processing changes ("start" would do the same)
|
|
72
118
|
listener.stop # stop both listening to changes and processing them
|
73
119
|
```
|
74
120
|
|
75
|
-
Note: While paused,
|
121
|
+
Note: While paused, `listen` keeps on collecting changes in the background - to clear them, call `stop`.
|
76
122
|
|
77
|
-
Note: You should keep track of all started listeners and stop them properly on finish.
|
123
|
+
Note: You should keep track of all started listeners and `stop` them properly on finish.
|
78
124
|
|
79
125
|
### Ignore / ignore!
|
80
126
|
|
81
|
-
Listen ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer)
|
127
|
+
`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
|
128
|
+
You can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.
|
82
129
|
|
83
130
|
``` ruby
|
84
131
|
listener = Listen.to('dir/path/to/listen', ignore: /\.txt/) { |modified, added, removed| # ... }
|
@@ -90,11 +137,11 @@ sleep
|
|
90
137
|
|
91
138
|
Note: `:ignore` regexp patterns are evaluated against relative paths.
|
92
139
|
|
93
|
-
Note: Ignoring paths does not improve performance, except when Polling ([#274](https://github.com/guard/listen/issues/274))
|
140
|
+
Note: Ignoring paths does not improve performance, except when Polling ([#274](https://github.com/guard/listen/issues/274)).
|
94
141
|
|
95
142
|
### Only
|
96
143
|
|
97
|
-
Listen
|
144
|
+
`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.
|
98
145
|
|
99
146
|
``` ruby
|
100
147
|
listener = Listen.to('dir/path/to/listen', only: /\.rb$/) { |modified, added, removed| # ... }
|
@@ -106,35 +153,6 @@ sleep
|
|
106
153
|
Note: `:only` regexp patterns are evaluated only against relative **file** paths.
|
107
154
|
|
108
155
|
|
109
|
-
## Changes callback
|
110
|
-
|
111
|
-
Changes to the listened-to directories gets reported back to the user in a callback.
|
112
|
-
The registered callback gets invoked, when there are changes, with **three** parameters:
|
113
|
-
`modified`, `added` and `removed` paths, in that particular order.
|
114
|
-
Paths are always returned in their absolute form.
|
115
|
-
|
116
|
-
Example:
|
117
|
-
|
118
|
-
```ruby
|
119
|
-
listener = Listen.to('path/to/app') do |modified, added, removed|
|
120
|
-
# This block will be called when there are changes.
|
121
|
-
end
|
122
|
-
listener.start
|
123
|
-
sleep
|
124
|
-
```
|
125
|
-
|
126
|
-
or ...
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
# Create a callback
|
130
|
-
callback = Proc.new do |modified, added, removed|
|
131
|
-
# This proc will be called when there are changes.
|
132
|
-
end
|
133
|
-
listener = Listen.to('dir', &callback)
|
134
|
-
listener.start
|
135
|
-
sleep
|
136
|
-
```
|
137
|
-
|
138
156
|
## Options
|
139
157
|
|
140
158
|
All the following options can be set through the `Listen.to` after the directory path(s) params.
|
@@ -164,16 +182,42 @@ polling_fallback_message: 'custom message' # Set a custom polling fallback
|
|
164
182
|
# default: "Listen will be polling for changes. Learn more at https://github.com/guard/listen#listen-adapters."
|
165
183
|
```
|
166
184
|
|
167
|
-
## Debugging
|
185
|
+
## Logging and Debugging
|
168
186
|
|
169
|
-
|
187
|
+
`Listen` logs its activity to `Listen.logger`.
|
188
|
+
This is the primary method of debugging.
|
170
189
|
|
171
|
-
|
190
|
+
### Custom Logger
|
191
|
+
You can call `Listen.logger =` to set a custom `listen` logger for the process. For example:
|
192
|
+
```
|
193
|
+
Listen.logger = Rails.logger
|
194
|
+
```
|
172
195
|
|
196
|
+
### Default Logger
|
197
|
+
If no custom logger is set, a default `listen` logger which logs to to `STDERR` will be created and assigned to `Listen.logger`.
|
173
198
|
|
174
|
-
|
199
|
+
The default logger defaults to the `error` logging level (severity).
|
200
|
+
You can override the logging level by setting the environment variable `LISTEN_GEM_DEBUGGING=<level>`.
|
201
|
+
For `<level>`, all standard `::Logger` levels are supported, with any mix of upper-/lower-case:
|
202
|
+
```
|
203
|
+
export LISTEN_GEM_DEBUGGING=debug # or 2 [deprecated]
|
204
|
+
export LISTEN_GEM_DEBUGGING=info # or 1 or true or yes [deprecated]
|
205
|
+
export LISTEN_GEM_DEBUGGING=warn
|
206
|
+
export LISTEN_GEM_DEBUGGING=fatal
|
207
|
+
export LISTEN_GEM_DEBUGGING=error
|
208
|
+
```
|
209
|
+
The default of `error` will be used if an unsupported value is set.
|
175
210
|
|
176
|
-
The
|
211
|
+
Note: The alternate values `1`, `2`, `true` and `yes` shown above are deprecated and will be removed from `listen` v4.0.
|
212
|
+
|
213
|
+
### Disabling Logging
|
214
|
+
If you want to disable `listen` logging, set
|
215
|
+
```
|
216
|
+
Listen.logger = ::Logger.new('/dev/null')
|
217
|
+
```
|
218
|
+
## Listen Adapters
|
219
|
+
|
220
|
+
The `Listen` gem has a set of adapters to notify it when there are changes.
|
177
221
|
|
178
222
|
There are 4 OS-specific adapters to support Darwin, Linux, \*BSD and Windows.
|
179
223
|
These adapters are fast as they use some system-calls to implement the notifying function.
|
@@ -181,9 +225,9 @@ These adapters are fast as they use some system-calls to implement the notifying
|
|
181
225
|
There is also a polling adapter - although it's much slower than other adapters,
|
182
226
|
it works on every platform/system and scenario (including network filesystems such as VM shared folders).
|
183
227
|
|
184
|
-
The Darwin and Linux adapters are dependencies of the
|
228
|
+
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.
|
185
229
|
|
186
|
-
The
|
230
|
+
The `listen` gem will choose the best adapter automatically, if present. If you
|
187
231
|
want to force the use of the polling adapter, use the `:force_polling` option
|
188
232
|
while initializing the listener.
|
189
233
|
|
@@ -194,7 +238,7 @@ If you are on Windows, it's recommended to use the [`wdm`](https://github.com/Ma
|
|
194
238
|
Please add the following to your Gemfile:
|
195
239
|
|
196
240
|
```ruby
|
197
|
-
gem 'wdm', '>= 0.1.0'
|
241
|
+
gem 'wdm', '>= 0.1.0', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
198
242
|
```
|
199
243
|
|
200
244
|
### On \*BSD
|
@@ -213,35 +257,144 @@ end
|
|
213
257
|
|
214
258
|
### Getting the [polling fallback message](#options)?
|
215
259
|
|
216
|
-
|
260
|
+
If you see:
|
261
|
+
```
|
262
|
+
Listen will be polling for changes.
|
263
|
+
```
|
217
264
|
|
218
|
-
|
265
|
+
This means the Listen gem can’t find an optimized adapter. Typically this is caused by:
|
219
266
|
|
220
|
-
|
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.
|
221
270
|
|
222
|
-
|
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).
|
336
|
+
|
337
|
+
### Issues and Troubleshooting
|
338
|
+
|
339
|
+
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).
|
340
|
+
|
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.*
|
342
|
+
|
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).
|
223
372
|
|
224
373
|
## Performance
|
225
374
|
|
226
|
-
If
|
375
|
+
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).
|
227
376
|
|
228
377
|
Also, if the directories you're watching contain many files, make sure you're:
|
229
378
|
|
230
379
|
* not using Polling (ideally)
|
231
380
|
* using `:ignore` and `:only` options to avoid tracking directories you don't care about (important with Polling and on MacOS)
|
232
|
-
* running
|
381
|
+
* running `listen` with the `:latency` and `:wait_for_delay` options not too small or too big (depends on needs)
|
233
382
|
* not watching directories with log files, database files or other frequently changing files
|
234
|
-
* not using a version of
|
235
|
-
* not getting silent crashes within
|
236
|
-
* not running multiple instances of
|
383
|
+
* not using a version of `listen` prior to 2.7.7
|
384
|
+
* not getting silent crashes within `listen` (see `LISTEN_GEM_DEBUGGING=debug`)
|
385
|
+
* not running multiple instances of `listen` in the background
|
237
386
|
* using a file system with atime modification disabled (ideally)
|
238
387
|
* not using a filesystem with inaccurate file modification times (ideally), e.g. HFS, VFAT
|
239
388
|
* not buffering to a slow terminal (e.g. transparency + fancy font + slow gfx card + lots of output)
|
240
389
|
* ideally not running a slow encryption stack, e.g. btrfs + ecryptfs
|
241
390
|
|
242
|
-
When in doubt, LISTEN_GEM_DEBUGGING=
|
391
|
+
When in doubt, `LISTEN_GEM_DEBUGGING=debug` can help discover the actual events and time they happened.
|
243
392
|
|
244
|
-
|
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)
|
245
398
|
|
246
399
|
## Development
|
247
400
|
|
@@ -259,11 +412,29 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
|
|
259
412
|
For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
|
260
413
|
`#guard` (irc.freenode.net).
|
261
414
|
|
415
|
+
## Releasing
|
416
|
+
|
417
|
+
### Prerequisites
|
418
|
+
|
419
|
+
* You must have commit rights to the GitHub repository.
|
420
|
+
* You must have push rights for rubygems.org.
|
421
|
+
|
422
|
+
### How to release
|
423
|
+
|
424
|
+
1. Run `bundle install` to make sure that you have all the gems necessary for testing and releasing.
|
425
|
+
2. **Ensure all tests are passing by running `bundle exec rake`.**
|
426
|
+
3. Determine which would be the correct next version number according to [semver](http://semver.org/).
|
427
|
+
4. Update the version in `./lib/listen/version.rb`.
|
428
|
+
5. Update the version in the Install section of `./README.md` (`gem 'listen', '~> X.Y'`).
|
429
|
+
6. Commit the version in a single commit, the message should be "Preparing vX.Y.Z"
|
430
|
+
7. Run `bundle exec rake release:full`; this will tag, push to GitHub, and publish to rubygems.org.
|
431
|
+
8. Update and publish the release notes on the [GitHub releases page](https://github.com/guard/listen/releases) if necessary
|
432
|
+
|
262
433
|
## Acknowledgments
|
263
434
|
|
264
435
|
* [Michael Kessler (netzpirat)][] for having written the [initial specs](https://github.com/guard/listen/commit/1e457b13b1bb8a25d2240428ce5ed488bafbed1f).
|
265
436
|
* [Travis Tilley (ttilley)][] for this awesome work on [fssm][] & [rb-fsevent][].
|
266
|
-
* [
|
437
|
+
* [Natalie Weizenbaum (nex3)][] for [rb-inotify][], a thorough inotify wrapper.
|
267
438
|
* [Mathieu Arnold (mat813)][] for [rb-kqueue][], a simple kqueue wrapper.
|
268
439
|
* [Maher Sallam][] for [wdm][], windows support wouldn't exist without him.
|
269
440
|
* [Yehuda Katz (wycats)][] for [vigilo][], that has been a great source of inspiration.
|
@@ -283,7 +454,7 @@ For questions please join us in our [Google group](http://groups.google.com/grou
|
|
283
454
|
[fssm]: https://github.com/ttilley/fssm
|
284
455
|
[rb-fsevent]: https://github.com/thibaudgg/rb-fsevent
|
285
456
|
[Mathieu Arnold (mat813)]: https://github.com/mat813
|
286
|
-
[
|
457
|
+
[Natalie Weizenbaum (nex3)]: https://github.com/nex3
|
287
458
|
[rb-inotify]: https://github.com/nex3/rb-inotify
|
288
459
|
[stereobooster]: https://github.com/stereobooster
|
289
460
|
[rb-fchange]: https://github.com/stereobooster/rb-fchange
|
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
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'listen/options'
|
2
4
|
require 'listen/record'
|
3
5
|
require 'listen/change'
|
6
|
+
require 'listen/thread'
|
4
7
|
|
5
8
|
module Listen
|
6
9
|
module Adapter
|
7
10
|
class Base
|
8
|
-
attr_reader :options
|
11
|
+
attr_reader :options, :config
|
9
12
|
|
10
13
|
# TODO: only used by tests
|
11
|
-
DEFAULTS = {}
|
12
|
-
|
13
|
-
attr_reader :config
|
14
|
+
DEFAULTS = {}.freeze
|
14
15
|
|
15
16
|
def initialize(config)
|
16
17
|
@started = false
|
@@ -28,9 +29,10 @@ module Listen
|
|
28
29
|
end
|
29
30
|
|
30
31
|
# TODO: it's a separate method as a temporary workaround for tests
|
32
|
+
# rubocop:disable Metrics/MethodLength
|
31
33
|
def configure
|
32
34
|
if @configured
|
33
|
-
|
35
|
+
Listen.logger.warn('Adapter already configured!')
|
34
36
|
return
|
35
37
|
end
|
36
38
|
|
@@ -54,6 +56,7 @@ module Listen
|
|
54
56
|
@snapshots[dir] = snapshot
|
55
57
|
end
|
56
58
|
end
|
59
|
+
# rubocop:enable Metrics/MethodLength
|
57
60
|
|
58
61
|
def started?
|
59
62
|
@started
|
@@ -63,48 +66,39 @@ module Listen
|
|
63
66
|
configure
|
64
67
|
|
65
68
|
if started?
|
66
|
-
|
69
|
+
Listen.logger.warn('Adapter already started!')
|
67
70
|
return
|
68
71
|
end
|
69
72
|
|
70
73
|
@started = true
|
71
74
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
@snapshots.values.each do |snapshot|
|
76
|
-
_timed('Record.build()') { snapshot.record.build }
|
77
|
-
end
|
78
|
-
_run
|
79
|
-
rescue
|
80
|
-
msg = 'run() in thread failed: %s:\n'\
|
81
|
-
' %s\n\ncalled from:\n %s'
|
82
|
-
_log_exception(msg, calling_stack)
|
83
|
-
raise # for unit tests mostly
|
75
|
+
@run_thread = Listen::Thread.new("run_thread") do
|
76
|
+
@snapshots.each_value do |snapshot|
|
77
|
+
_timed('Record.build()') { snapshot.record.build }
|
84
78
|
end
|
79
|
+
_run
|
85
80
|
end
|
86
81
|
end
|
87
82
|
|
88
83
|
def stop
|
89
84
|
_stop
|
90
|
-
|
91
|
-
|
92
|
-
def self.usable?
|
93
|
-
const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os']
|
85
|
+
config.queue.close # this causes queue.pop to return `nil` to the front-end
|
94
86
|
end
|
95
87
|
|
96
88
|
private
|
97
89
|
|
98
90
|
def _stop
|
91
|
+
@run_thread&.kill
|
92
|
+
@run_thread = nil
|
99
93
|
end
|
100
94
|
|
101
95
|
def _timed(title)
|
102
|
-
start =
|
96
|
+
start = MonotonicTime.now
|
103
97
|
yield
|
104
|
-
diff =
|
105
|
-
Listen
|
98
|
+
diff = MonotonicTime.now - start
|
99
|
+
Listen.logger.info format('%s: %.05f seconds', title, diff)
|
106
100
|
rescue
|
107
|
-
Listen
|
101
|
+
Listen.logger.warn "#{title} crashed: #{$ERROR_INFO.inspect}"
|
108
102
|
raise
|
109
103
|
end
|
110
104
|
|
@@ -114,10 +108,6 @@ module Listen
|
|
114
108
|
@snapshots[dir].invalidate(type, rel_path, options)
|
115
109
|
end
|
116
110
|
|
117
|
-
def _log(*args, &block)
|
118
|
-
self.class.send(:_log, *args, &block)
|
119
|
-
end
|
120
|
-
|
121
111
|
def _log_exception(msg, caller_stack)
|
122
112
|
formatted = format(
|
123
113
|
msg,
|
@@ -126,11 +116,13 @@ module Listen
|
|
126
116
|
caller_stack * "\n"
|
127
117
|
)
|
128
118
|
|
129
|
-
|
119
|
+
Listen.logger.error(formatted)
|
130
120
|
end
|
131
121
|
|
132
|
-
|
133
|
-
|
122
|
+
class << self
|
123
|
+
def usable?
|
124
|
+
const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os']
|
125
|
+
end
|
134
126
|
end
|
135
127
|
end
|
136
128
|
end
|