filewatcher 1.0.1 → 1.1.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 +5 -5
- data/bin/filewatcher +11 -11
- data/lib/filewatcher.rb +6 -3
- data/lib/filewatcher/version.rb +1 -1
- data/test/helper.rb +35 -13
- data/test/test_filewatcher.rb +6 -3
- metadata +8 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed73f2615aeb5418438bb443abc274bc2cd8279f
|
4
|
+
data.tar.gz: 716e8b582f81531d486c1a281149da1702a044b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b37524eaae72f8eaaad40766e4e1793ec5766ebe7dd454e310eb98ba54745c59ecbc8358ea2045e335d242c84d6e48ef5bc1d0718b75546af481bd221f25c5d9
|
7
|
+
data.tar.gz: 50690825a35a747dce1491d7f3f77a2edf135797551ca625cdeeafb08efd31caada6e982de54fde6bdad88d4ae934b92bb66d29605a7d74e181bc5d059f9d367
|
data/bin/filewatcher
CHANGED
@@ -5,10 +5,10 @@ require_relative '../lib/filewatcher'
|
|
5
5
|
require_relative '../lib/filewatcher/env'
|
6
6
|
require_relative '../lib/filewatcher/runner'
|
7
7
|
require_relative '../lib/filewatcher/version'
|
8
|
-
require 'trollop'
|
9
|
-
require 'thread'
|
10
8
|
|
11
|
-
|
9
|
+
require 'optimist'
|
10
|
+
|
11
|
+
options = Optimist.options do
|
12
12
|
version "filewatcher, version #{Filewatcher::VERSION} by Thomas Flemming 2016"
|
13
13
|
banner File.read File.join(__dir__, 'banner.txt')
|
14
14
|
|
@@ -33,7 +33,7 @@ options = Trollop.options do
|
|
33
33
|
short: 's', type: :boolean, default: false
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
Optimist.die Optimist.educate if ARGV.empty?
|
37
37
|
|
38
38
|
files = ARGV[0..-2]
|
39
39
|
|
@@ -50,13 +50,13 @@ end
|
|
50
50
|
files = split_files_void_escaped_whitespace(files)
|
51
51
|
child_pid = nil
|
52
52
|
|
53
|
-
def restart(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
rescue Errno::ESRCH
|
58
|
-
|
59
|
-
|
53
|
+
def restart(pid, env, cmd)
|
54
|
+
begin
|
55
|
+
Process.kill(9, pid)
|
56
|
+
Process.wait(pid)
|
57
|
+
rescue Errno::ESRCH
|
58
|
+
nil # already killed
|
59
|
+
end
|
60
60
|
Process.spawn(env, cmd)
|
61
61
|
end
|
62
62
|
|
data/lib/filewatcher.rb
CHANGED
@@ -29,7 +29,12 @@ class Filewatcher
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def watch(&on_update)
|
32
|
-
|
32
|
+
## The set of available signals depends on the OS
|
33
|
+
## Windows doesn't support `HUP` signal, for example
|
34
|
+
(%w[HUP INT TERM] & Signal.list.keys).each do |signal|
|
35
|
+
trap(signal) { exit }
|
36
|
+
end
|
37
|
+
|
33
38
|
@on_update = on_update
|
34
39
|
@keep_watching = true
|
35
40
|
yield('', '') if @immediate
|
@@ -105,8 +110,6 @@ class Filewatcher
|
|
105
110
|
def filesystem_updated?(snapshot = mtime_snapshot)
|
106
111
|
@changes = {}
|
107
112
|
|
108
|
-
# rubocop:disable Perfomance/HashEachMethods
|
109
|
-
## https://github.com/bbatsov/rubocop/issues/4732
|
110
113
|
(snapshot.to_a - last_snapshot.to_a).each do |file, _mtime|
|
111
114
|
@changes[file] = last_snapshot[file] ? :updated : :created
|
112
115
|
end
|
data/lib/filewatcher/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -20,7 +20,7 @@ class WatchRun
|
|
20
20
|
action: :update
|
21
21
|
)
|
22
22
|
@filename =
|
23
|
-
filename
|
23
|
+
filename =~ %r{^(/|~|[A-Z]:)} ? filename : File.join(TMP_DIR, filename)
|
24
24
|
@directory = directory
|
25
25
|
@action = action
|
26
26
|
end
|
@@ -55,6 +55,8 @@ class WatchRun
|
|
55
55
|
end
|
56
56
|
|
57
57
|
class RubyWatchRun < WatchRun
|
58
|
+
SLEEP_MULTIPLIER = Gem::Platform.local.os == 'darwin' ? 5 : 1
|
59
|
+
|
58
60
|
attr_reader :filewatcher, :thread, :watched, :processed
|
59
61
|
|
60
62
|
def initialize(
|
@@ -72,18 +74,24 @@ class RubyWatchRun < WatchRun
|
|
72
74
|
super
|
73
75
|
@thread = thread_initialize
|
74
76
|
# thread needs a chance to start
|
75
|
-
wait
|
77
|
+
wait 12 do
|
76
78
|
filewatcher.keep_watching
|
77
79
|
end
|
80
|
+
|
81
|
+
# a little more time
|
82
|
+
sleep 1 * SLEEP_MULTIPLIER
|
78
83
|
end
|
79
84
|
|
80
85
|
def stop
|
81
86
|
thread.exit
|
82
87
|
|
83
|
-
wait
|
88
|
+
wait 12 do
|
84
89
|
thread.stop?
|
85
90
|
end
|
86
91
|
|
92
|
+
# a little more time
|
93
|
+
sleep 1 * SLEEP_MULTIPLIER
|
94
|
+
|
87
95
|
super
|
88
96
|
end
|
89
97
|
|
@@ -94,7 +102,7 @@ class RubyWatchRun < WatchRun
|
|
94
102
|
|
95
103
|
# Some OS, filesystems and Ruby interpretators
|
96
104
|
# doesn't catch milliseconds of `File.mtime`
|
97
|
-
wait
|
105
|
+
wait 12 do
|
98
106
|
processed.any?
|
99
107
|
end
|
100
108
|
end
|
@@ -149,11 +157,7 @@ class ShellWatchRun < WatchRun
|
|
149
157
|
def start
|
150
158
|
super
|
151
159
|
|
152
|
-
@pid =
|
153
|
-
"#{EXECUTABLE} #{@options_string} \"#{@filename}\"" \
|
154
|
-
" \"ruby #{File.join(__dir__, 'dumpers', "#{@dumper}_dumper.rb")}\"",
|
155
|
-
pgroup: true
|
156
|
-
)
|
160
|
+
@pid = spawn_filewatcher
|
157
161
|
|
158
162
|
Process.detach(@pid)
|
159
163
|
|
@@ -166,10 +170,7 @@ class ShellWatchRun < WatchRun
|
|
166
170
|
end
|
167
171
|
|
168
172
|
def stop
|
169
|
-
|
170
|
-
## Solution: https://stackoverflow.com/a/45032252/2630849
|
171
|
-
Process.kill('TERM', -Process.getpgid(@pid))
|
172
|
-
Process.waitall
|
173
|
+
kill_filewatcher
|
173
174
|
|
174
175
|
wait 12 do
|
175
176
|
pid_state.empty?
|
@@ -183,6 +184,16 @@ class ShellWatchRun < WatchRun
|
|
183
184
|
|
184
185
|
private
|
185
186
|
|
187
|
+
SPAWN_OPTIONS = Gem.win_platform? ? {} : { pgroup: true }
|
188
|
+
|
189
|
+
def spawn_filewatcher
|
190
|
+
spawn(
|
191
|
+
"#{EXECUTABLE} #{@options_string} \"#{@filename}\"" \
|
192
|
+
" \"ruby #{File.join(__dir__, "dumpers/#{@dumper}_dumper.rb")}\"",
|
193
|
+
**SPAWN_OPTIONS
|
194
|
+
)
|
195
|
+
end
|
196
|
+
|
186
197
|
def make_changes
|
187
198
|
super
|
188
199
|
|
@@ -191,6 +202,17 @@ class ShellWatchRun < WatchRun
|
|
191
202
|
end
|
192
203
|
end
|
193
204
|
|
205
|
+
def kill_filewatcher
|
206
|
+
if Gem.win_platform?
|
207
|
+
Process.kill('KILL', @pid)
|
208
|
+
else
|
209
|
+
## Problems: https://github.com/thomasfl/filewatcher/pull/83
|
210
|
+
## Solution: https://stackoverflow.com/a/45032252/2630849
|
211
|
+
Process.kill('TERM', -Process.getpgid(@pid))
|
212
|
+
Process.waitall
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
194
216
|
def pid_state
|
195
217
|
## For macOS output:
|
196
218
|
## https://travis-ci.org/thomasfl/filewatcher/jobs/304433538
|
data/test/test_filewatcher.rb
CHANGED
@@ -212,13 +212,15 @@ describe Filewatcher do
|
|
212
212
|
(1..4).each do |n|
|
213
213
|
File.write("test/tmp/file#{n}.txt", "content#{n}")
|
214
214
|
end
|
215
|
-
|
215
|
+
# Give filewatcher time to respond
|
216
|
+
sleep 1 * RubyWatchRun::SLEEP_MULTIPLIER
|
216
217
|
|
217
218
|
# update block should not have been called
|
218
219
|
wr.processed.should.be.empty
|
219
220
|
|
220
221
|
wr.filewatcher.resume
|
221
|
-
|
222
|
+
# Give filewatcher time to respond
|
223
|
+
sleep 1 * RubyWatchRun::SLEEP_MULTIPLIER
|
222
224
|
|
223
225
|
# update block still should not have been called
|
224
226
|
wr.processed.should.be.empty
|
@@ -227,7 +229,8 @@ describe Filewatcher do
|
|
227
229
|
File.write(file = "test/tmp/file#{n}.txt", "content#{n}")
|
228
230
|
file
|
229
231
|
end
|
230
|
-
|
232
|
+
# Give filewatcher time to respond
|
233
|
+
sleep 1 * RubyWatchRun::SLEEP_MULTIPLIER
|
231
234
|
|
232
235
|
wr.filewatcher.stop
|
233
236
|
wr.stop
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bacon
|
@@ -25,25 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: optimist
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 2.1.2
|
33
|
+
version: '3.0'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 2.1.2
|
40
|
+
version: '3.0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rake
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,14 +58,14 @@ dependencies:
|
|
64
58
|
requirements:
|
65
59
|
- - "~>"
|
66
60
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0.
|
61
|
+
version: '0.57'
|
68
62
|
type: :development
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
66
|
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version: '0.
|
68
|
+
version: '0.57'
|
75
69
|
description: Detect changes in filesystem. Works anywhere.
|
76
70
|
email:
|
77
71
|
- thomas.flemming@gmail.com
|
@@ -114,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
108
|
version: '0'
|
115
109
|
requirements: []
|
116
110
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.6.14.1
|
118
112
|
signing_key:
|
119
113
|
specification_version: 4
|
120
114
|
summary: Lighweight filewatcher.
|