listen 3.2.1 → 3.3.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 +4 -4
- data/README.md +110 -65
- data/lib/listen.rb +15 -20
- data/lib/listen/adapter.rb +6 -8
- data/lib/listen/adapter/base.rb +17 -29
- data/lib/listen/adapter/bsd.rb +3 -1
- data/lib/listen/adapter/config.rb +2 -0
- data/lib/listen/adapter/darwin.rb +10 -12
- data/lib/listen/adapter/linux.rb +7 -4
- data/lib/listen/adapter/polling.rb +2 -0
- data/lib/listen/adapter/windows.rb +6 -4
- data/lib/listen/backend.rb +2 -0
- data/lib/listen/change.rb +5 -3
- data/lib/listen/cli.rb +3 -2
- data/lib/listen/directory.rb +4 -2
- data/lib/listen/event/config.rb +8 -18
- data/lib/listen/event/loop.rb +41 -65
- data/lib/listen/event/processor.rb +31 -25
- data/lib/listen/event/queue.rb +4 -5
- data/lib/listen/file.rb +9 -2
- data/lib/listen/fsm.rb +69 -71
- data/lib/listen/listener.rb +24 -23
- data/lib/listen/listener/config.rb +2 -0
- data/lib/listen/logger.rb +27 -24
- data/lib/listen/options.rb +3 -1
- data/lib/listen/queue_optimizer.rb +2 -0
- data/lib/listen/record.rb +16 -2
- data/lib/listen/record/entry.rb +3 -1
- data/lib/listen/record/symlink_detector.rb +2 -0
- data/lib/listen/silencer.rb +2 -0
- data/lib/listen/silencer/controller.rb +2 -0
- data/lib/listen/thread.rb +52 -0
- data/lib/listen/version.rb +3 -1
- metadata +7 -23
- data/lib/listen/internals/thread_pool.rb +0 -29
data/lib/listen/logger.rb
CHANGED
@@ -1,32 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Listen
|
2
|
-
|
3
|
-
@logger ||= nil
|
4
|
-
end
|
4
|
+
@logger = nil
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# Listen.logger will always be present.
|
7
|
+
# If you don't want logging, set Listen.logger = ::Logger.new('/dev/null', level: ::Logger::UNKNOWN)
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_writer :logger
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
debugging = ENV['LISTEN_GEM_DEBUGGING']
|
13
|
-
logger.level =
|
14
|
-
case debugging.to_s
|
15
|
-
when /2/
|
16
|
-
::Logger::DEBUG
|
17
|
-
when /true|yes|1/i
|
18
|
-
::Logger::INFO
|
19
|
-
else
|
20
|
-
::Logger::ERROR
|
21
|
-
end
|
12
|
+
def logger
|
13
|
+
@logger ||= default_logger
|
22
14
|
end
|
23
|
-
end
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_logger
|
19
|
+
level = case ENV['LISTEN_GEM_DEBUGGING'].to_s
|
20
|
+
when /debug|2/i
|
21
|
+
::Logger::DEBUG
|
22
|
+
when /info|true|yes|1/i
|
23
|
+
::Logger::INFO
|
24
|
+
when /warn/i
|
25
|
+
::Logger::WARN
|
26
|
+
when /fatal/i
|
27
|
+
::Logger::FATAL
|
28
|
+
else
|
29
|
+
::Logger::ERROR
|
30
|
+
end
|
31
|
+
|
32
|
+
::Logger.new(STDERR, level: level)
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
data/lib/listen/options.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Listen
|
2
4
|
class Options
|
3
5
|
def initialize(opts, defaults)
|
@@ -10,7 +12,7 @@ module Listen
|
|
10
12
|
return if given_options.empty?
|
11
13
|
|
12
14
|
msg = "Unknown options: #{given_options.inspect}"
|
13
|
-
Listen
|
15
|
+
Listen.logger.warn msg
|
14
16
|
fail msg
|
15
17
|
end
|
16
18
|
|
data/lib/listen/record.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'thread'
|
2
4
|
require 'listen/record/entry'
|
3
5
|
require 'listen/record/symlink_detector'
|
@@ -45,8 +47,7 @@ module Listen
|
|
45
47
|
if [nil, '', '.'].include? rel_path.to_s
|
46
48
|
tree
|
47
49
|
else
|
48
|
-
|
49
|
-
tree[rel_path.to_s]
|
50
|
+
_sub_tree(rel_path)
|
50
51
|
end
|
51
52
|
|
52
53
|
result = {}
|
@@ -57,6 +58,19 @@ module Listen
|
|
57
58
|
result
|
58
59
|
end
|
59
60
|
|
61
|
+
def _sub_tree(rel_path)
|
62
|
+
tree.each_with_object({}) do |(path, meta), result|
|
63
|
+
next unless path.start_with?(rel_path)
|
64
|
+
|
65
|
+
if path == rel_path
|
66
|
+
result.merge!(meta)
|
67
|
+
else
|
68
|
+
sub_path = path.sub(%r{\A#{rel_path}/?}, '')
|
69
|
+
result[sub_path] = meta
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
60
74
|
def build
|
61
75
|
@tree = _auto_hash
|
62
76
|
# TODO: test with a file name given
|
data/lib/listen/record/entry.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Listen
|
2
4
|
# @private api
|
3
5
|
class Record
|
@@ -22,7 +24,7 @@ module Listen
|
|
22
24
|
|
23
25
|
def meta
|
24
26
|
lstat = ::File.lstat(sys_path)
|
25
|
-
{ mtime: lstat.mtime.to_f, mode: lstat.mode }
|
27
|
+
{ mtime: lstat.mtime.to_f, mode: lstat.mode, size: lstat.size }
|
26
28
|
end
|
27
29
|
|
28
30
|
# record hash is e.g.
|
data/lib/listen/silencer.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thread'
|
4
|
+
|
5
|
+
require_relative 'logger'
|
6
|
+
|
7
|
+
module Listen
|
8
|
+
module Thread
|
9
|
+
class << self
|
10
|
+
# Creates a new thread with the given name.
|
11
|
+
# Any exceptions raised by the thread will be logged with the thread name and complete backtrace.
|
12
|
+
def new(name, &block)
|
13
|
+
thread_name = "listen-#{name}"
|
14
|
+
caller_stack = caller
|
15
|
+
|
16
|
+
::Thread.new do
|
17
|
+
rescue_and_log(thread_name, caller_stack: caller_stack, &block)
|
18
|
+
end.tap do |thread|
|
19
|
+
thread.name = thread_name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def rescue_and_log(method_name, *args, caller_stack: nil)
|
24
|
+
yield(*args)
|
25
|
+
rescue Exception => ex
|
26
|
+
_log_exception(ex, method_name, caller_stack: caller_stack)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def _log_exception(ex, thread_name, caller_stack: nil)
|
32
|
+
complete_backtrace = if caller_stack
|
33
|
+
[*ex.backtrace, "--- Thread.new ---", *caller_stack]
|
34
|
+
else
|
35
|
+
ex.backtrace
|
36
|
+
end
|
37
|
+
message = "Exception rescued in #{thread_name}:\n#{_exception_with_causes(ex)}\n#{complete_backtrace * "\n"}"
|
38
|
+
Listen.logger.error(message)
|
39
|
+
end
|
40
|
+
|
41
|
+
def _exception_with_causes(ex)
|
42
|
+
result = +"#{ex.class}: #{ex}"
|
43
|
+
if ex.cause
|
44
|
+
result << "\n"
|
45
|
+
result << "--- Caused by: ---\n"
|
46
|
+
result << _exception_with_causes(ex.cause)
|
47
|
+
end
|
48
|
+
result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/listen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: listen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaud Guillaume-Gentil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb-fsevent
|
@@ -50,22 +50,8 @@ dependencies:
|
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 0.9.10
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: bundler
|
55
|
-
requirement: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '0'
|
60
|
-
type: :development
|
61
|
-
prerelease: false
|
62
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '0'
|
67
53
|
description: The Listen gem listens to file modifications and notifies you about the
|
68
|
-
|
54
|
+
changegem. Works everywhere!
|
69
55
|
email: thibaud@thibaud.gg
|
70
56
|
executables:
|
71
57
|
- listen
|
@@ -96,7 +82,6 @@ files:
|
|
96
82
|
- lib/listen/event/queue.rb
|
97
83
|
- lib/listen/file.rb
|
98
84
|
- lib/listen/fsm.rb
|
99
|
-
- lib/listen/internals/thread_pool.rb
|
100
85
|
- lib/listen/listener.rb
|
101
86
|
- lib/listen/listener/config.rb
|
102
87
|
- lib/listen/logger.rb
|
@@ -107,20 +92,19 @@ files:
|
|
107
92
|
- lib/listen/record/symlink_detector.rb
|
108
93
|
- lib/listen/silencer.rb
|
109
94
|
- lib/listen/silencer/controller.rb
|
95
|
+
- lib/listen/thread.rb
|
110
96
|
- lib/listen/version.rb
|
111
97
|
homepage: https://github.com/guard/listen
|
112
98
|
licenses:
|
113
99
|
- MIT
|
114
|
-
metadata:
|
100
|
+
metadata:
|
101
|
+
allowed_push_host: https://rubygems.org
|
115
102
|
post_install_message:
|
116
103
|
rdoc_options: []
|
117
104
|
require_paths:
|
118
105
|
- lib
|
119
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
107
|
requirements:
|
121
|
-
- - "~>"
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '2.2'
|
124
108
|
- - ">="
|
125
109
|
- !ruby/object:Gem::Version
|
126
110
|
version: 2.2.7
|
@@ -130,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
114
|
- !ruby/object:Gem::Version
|
131
115
|
version: '0'
|
132
116
|
requirements: []
|
133
|
-
rubygems_version: 3.0.
|
117
|
+
rubygems_version: 3.0.1
|
134
118
|
signing_key:
|
135
119
|
specification_version: 4
|
136
120
|
summary: Listen to file modifications
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Listen
|
2
|
-
# @private api
|
3
|
-
module Internals
|
4
|
-
module ThreadPool
|
5
|
-
def self.add(&block)
|
6
|
-
Thread.new { block.call }.tap do |th|
|
7
|
-
(@threads ||= Queue.new) << th
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.stop
|
12
|
-
return unless @threads ||= nil
|
13
|
-
return if @threads.empty? # return to avoid using possibly stubbed Queue
|
14
|
-
|
15
|
-
killed = Queue.new
|
16
|
-
# You can't kill a read on a descriptor in JRuby, so let's just
|
17
|
-
# ignore running threads (listen rb-inotify waiting for disk activity
|
18
|
-
# before closing) pray threads die faster than they are created...
|
19
|
-
limit = RUBY_ENGINE == 'jruby' ? [1] : []
|
20
|
-
|
21
|
-
killed << @threads.pop.kill until @threads.empty?
|
22
|
-
until killed.empty?
|
23
|
-
th = killed.pop
|
24
|
-
th.join(*limit) unless th[:listen_blocking_read_thread]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|