listen 3.1.3 → 3.3.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +8 -1
- data/README.md +29 -11
- data/lib/listen.rb +15 -25
- 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 +29 -44
- data/lib/listen/adapter/linux.rb +6 -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 +10 -2
- data/lib/listen/event/config.rb +8 -18
- data/lib/listen/event/loop.rb +43 -64
- data/lib/listen/event/processor.rb +26 -24
- 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 +25 -24
- 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 +6 -4
- 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 +5 -0
- data/lib/listen/silencer/controller.rb +2 -0
- data/lib/listen/thread.rb +47 -0
- data/lib/listen/version.rb +3 -1
- metadata +16 -48
- data/lib/listen/internals/thread_pool.rb +0 -29
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Listen
|
2
4
|
class QueueOptimizer
|
3
5
|
class Config
|
@@ -107,15 +109,15 @@ module Listen
|
|
107
109
|
def _detect_possible_editor_save(changes)
|
108
110
|
return unless changes.size == 2
|
109
111
|
|
110
|
-
from_type =
|
111
|
-
to_type =
|
112
|
+
from_type = from = nil
|
113
|
+
to_type = to_dir = to = nil
|
112
114
|
|
113
115
|
changes.each do |data|
|
114
116
|
case data[1]
|
115
117
|
when :moved_from
|
116
|
-
from_type,
|
118
|
+
from_type, _from_change, _, from, = data
|
117
119
|
when :moved_to
|
118
|
-
to_type,
|
120
|
+
to_type, _to_change, to_dir, to, = data
|
119
121
|
else
|
120
122
|
return nil
|
121
123
|
end
|
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
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Listen
|
2
4
|
class Silencer
|
3
5
|
# The default list of directories that get ignored.
|
@@ -46,6 +48,9 @@ module Listen
|
|
46
48
|
)
|
47
49
|
)
|
48
50
|
|
51
|
+
# Mutagen sync temporary files
|
52
|
+
| \.mutagen-temporary.*
|
53
|
+
|
49
54
|
# other files
|
50
55
|
| \.DS_Store
|
51
56
|
| \.tmp
|
@@ -0,0 +1,47 @@
|
|
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)
|
13
|
+
thread_name = "listen-#{name}"
|
14
|
+
|
15
|
+
caller_stack = caller
|
16
|
+
::Thread.new do
|
17
|
+
begin
|
18
|
+
yield
|
19
|
+
rescue Exception => ex
|
20
|
+
_log_exception(ex, thread_name, caller_stack)
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end.tap do |thread|
|
24
|
+
thread.name = thread_name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def _log_exception(ex, thread_name, caller_stack)
|
31
|
+
complete_backtrace = [*ex.backtrace, "--- Thread.new ---", *caller_stack]
|
32
|
+
message = "Exception rescued in #{thread_name}:\n#{_exception_with_causes(ex)}\n#{complete_backtrace * "\n"}"
|
33
|
+
Listen.logger.error(message)
|
34
|
+
end
|
35
|
+
|
36
|
+
def _exception_with_causes(ex)
|
37
|
+
result = +"#{ex.class}: #{ex}"
|
38
|
+
if ex.cause
|
39
|
+
result << "\n"
|
40
|
+
result << "--- Caused by: ---\n"
|
41
|
+
result << _exception_with_causes(ex.cause)
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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.0.pre.2
|
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-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb-fsevent
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.10'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.10.3
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0.
|
29
|
+
version: '0.10'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.10.3
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rb-inotify
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '0.9'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.9.
|
42
|
+
version: 0.9.10
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,37 +49,9 @@ dependencies:
|
|
49
49
|
version: '0.9'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.9.
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: ruby_dep
|
55
|
-
requirement: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - "~>"
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '1.2'
|
60
|
-
type: :runtime
|
61
|
-
prerelease: false
|
62
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - "~>"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '1.2'
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: bundler
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - "~>"
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '1.12'
|
74
|
-
type: :development
|
75
|
-
prerelease: false
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- - "~>"
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: '1.12'
|
52
|
+
version: 0.9.10
|
81
53
|
description: The Listen gem listens to file modifications and notifies you about the
|
82
|
-
|
54
|
+
changegem. Works everywhere!
|
83
55
|
email: thibaud@thibaud.gg
|
84
56
|
executables:
|
85
57
|
- listen
|
@@ -110,7 +82,6 @@ files:
|
|
110
82
|
- lib/listen/event/queue.rb
|
111
83
|
- lib/listen/file.rb
|
112
84
|
- lib/listen/fsm.rb
|
113
|
-
- lib/listen/internals/thread_pool.rb
|
114
85
|
- lib/listen/listener.rb
|
115
86
|
- lib/listen/listener/config.rb
|
116
87
|
- lib/listen/logger.rb
|
@@ -121,33 +92,30 @@ files:
|
|
121
92
|
- lib/listen/record/symlink_detector.rb
|
122
93
|
- lib/listen/silencer.rb
|
123
94
|
- lib/listen/silencer/controller.rb
|
95
|
+
- lib/listen/thread.rb
|
124
96
|
- lib/listen/version.rb
|
125
97
|
homepage: https://github.com/guard/listen
|
126
98
|
licenses:
|
127
99
|
- MIT
|
128
|
-
metadata:
|
100
|
+
metadata:
|
101
|
+
allowed_push_host: https://rubygems.org
|
129
102
|
post_install_message:
|
130
103
|
rdoc_options: []
|
131
104
|
require_paths:
|
132
105
|
- lib
|
133
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
107
|
requirements:
|
135
|
-
- - "~>"
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: '2.2'
|
138
108
|
- - ">="
|
139
109
|
- !ruby/object:Gem::Version
|
140
|
-
version: 2.2.
|
110
|
+
version: 2.2.7
|
141
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
112
|
requirements:
|
143
|
-
- - "
|
113
|
+
- - ">"
|
144
114
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
115
|
+
version: 1.3.1
|
146
116
|
requirements: []
|
147
|
-
|
148
|
-
rubygems_version: 2.5.1
|
117
|
+
rubygems_version: 3.0.1
|
149
118
|
signing_key:
|
150
119
|
specification_version: 4
|
151
120
|
summary: Listen to file modifications
|
152
121
|
test_files: []
|
153
|
-
has_rdoc:
|
@@ -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
|