filewatch 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filewatch/observing_tail.rb +2 -0
- data/lib/filewatch/tail.rb +3 -5
- data/lib/filewatch/tail_base.rb +0 -2
- data/lib/filewatch/watch.rb +129 -109
- data/lib/filewatch/yielding_tail.rb +2 -0
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e80ef8ef31b018ae2e8bcca3794c6389efbe9668
|
4
|
+
data.tar.gz: bf76dc26caa7715951a657769ad64a9bda8b5ca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63156fc561b37940e580a9bcbee7d2649f9b1ba24f8c16cb58830a9850baf2734c7f9ef6dbd0ba2cd4d5efcabf8d26c6f0f69dffca36ce7b0b388b6c9ea5f4d8
|
7
|
+
data.tar.gz: a0b76e79c2393bb8d05ceb6a18378e750c7eec25a7c4df61da066bacd0cc1f6b2f2c0e1287d629768a846ba4bb32dd9c7c56727b098a9cf2a49de5c6dc7dbfac
|
data/lib/filewatch/tail.rb
CHANGED
@@ -11,13 +11,11 @@ module FileWatch
|
|
11
11
|
attr_writer :target
|
12
12
|
|
13
13
|
def self.new_observing(opts = {})
|
14
|
-
new.
|
15
|
-
instance.target = ObservingTail.new(opts)
|
16
|
-
end
|
14
|
+
new({}, ObservingTail.new(opts))
|
17
15
|
end
|
18
16
|
|
19
|
-
def initialize(opts = {})
|
20
|
-
@target =
|
17
|
+
def initialize(opts = {}, target = YieldingTail.new(opts))
|
18
|
+
@target = target
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
data/lib/filewatch/tail_base.rb
CHANGED
@@ -209,8 +209,6 @@ module FileWatch
|
|
209
209
|
# before the instance is disposed of.
|
210
210
|
def quit
|
211
211
|
@watch.quit # <-- should close all the files
|
212
|
-
# and that should allow the sincedb_write to succeed if it could not before
|
213
|
-
_sincedb_write
|
214
212
|
end # def quit
|
215
213
|
|
216
214
|
public
|
data/lib/filewatch/watch.rb
CHANGED
@@ -117,127 +117,147 @@ module FileWatch
|
|
117
117
|
def each(&block)
|
118
118
|
synchronized do
|
119
119
|
return if @files.empty?
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
120
|
+
begin
|
121
|
+
file_deletable = []
|
122
|
+
# creates this array just once
|
123
|
+
watched_files = @files.values
|
124
|
+
|
125
|
+
# look at the closed to see if its changed
|
126
|
+
watched_files.select {|wf| wf.closed? }.each do |watched_file|
|
127
|
+
path = watched_file.path
|
128
|
+
break if quit?
|
129
|
+
begin
|
130
|
+
stat = watched_file.restat
|
131
|
+
if watched_file.size_changed? || watched_file.inode_changed?(inode(path,stat))
|
132
|
+
# if the closed file changed, move it to the watched state
|
133
|
+
# not to active state because we want to use MAX_OPEN_FILES throttling.
|
134
|
+
watched_file.watch
|
135
|
+
end
|
136
|
+
rescue Errno::ENOENT
|
137
|
+
# file has gone away or we can't read it anymore.
|
138
|
+
file_deletable << path
|
139
|
+
@logger.debug? && @logger.debug("each: closed?: stat failed: #{path}: (#{$!}), deleting from @files")
|
140
|
+
rescue => e
|
141
|
+
@logger.error("each: closed?: #{path}: (#{e.inspect})")
|
134
142
|
end
|
135
|
-
rescue Errno::ENOENT
|
136
|
-
# file has gone away or we can't read it anymore.
|
137
|
-
file_deleteable << path
|
138
|
-
@logger.debug? && @logger.debug("each: closed: stat failed: #{path}: (#{$!}), deleting from @files")
|
139
|
-
rescue => e
|
140
|
-
@logger.debug? && @logger.debug("each: closed: stat failed: #{path}: (#{e.inspect})")
|
141
143
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
144
|
+
return if quit?
|
145
|
+
|
146
|
+
# look at the ignored to see if its changed
|
147
|
+
watched_files.select {|wf| wf.ignored? }.each do |watched_file|
|
148
|
+
path = watched_file.path
|
149
|
+
break if quit?
|
150
|
+
begin
|
151
|
+
stat = watched_file.restat
|
152
|
+
if watched_file.size_changed? || watched_file.inode_changed?(inode(path,stat))
|
153
|
+
# if the ignored file changed, move it to the watched state
|
154
|
+
# not to active state because we want to use MAX_OPEN_FILES throttling.
|
155
|
+
# this file has not been yielded to the block yet
|
156
|
+
# but we must have the tail to start from the end, so when the file
|
157
|
+
# was first ignored we updated the bytes_read to the stat.size at that time.
|
158
|
+
# by adding this to the sincedb so that the subsequent modify
|
159
|
+
# event can detect the change
|
160
|
+
watched_file.watch
|
161
|
+
yield(:unignore, watched_file)
|
162
|
+
end
|
163
|
+
rescue Errno::ENOENT
|
164
|
+
# file has gone away or we can't read it anymore.
|
165
|
+
file_deletable << path
|
166
|
+
@logger.debug? && @logger.debug("each: ignored: stat failed: #{path}: (#{$!}), deleting from @files")
|
167
|
+
rescue => e
|
168
|
+
@logger.error("each: ignored?: #{path}: (#{e.inspect})")
|
159
169
|
end
|
160
|
-
rescue Errno::ENOENT
|
161
|
-
# file has gone away or we can't read it anymore.
|
162
|
-
file_deleteable << path
|
163
|
-
@logger.debug? && @logger.debug("each: ignored: stat failed: #{path}: (#{$!}), deleting from @files")
|
164
|
-
rescue => e
|
165
|
-
@logger.debug? && @logger.debug("each: ignored: stat failed: #{path}: (#{e.inspect})")
|
166
170
|
end
|
167
|
-
end
|
168
171
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
172
|
+
return if quit?
|
173
|
+
|
174
|
+
# Send any creates.
|
175
|
+
if (to_take = @max_active - watched_files.count{|wf| wf.active?}) > 0
|
176
|
+
watched_files.select {|wf| wf.watched? }.take(to_take).each do |watched_file|
|
177
|
+
break if quit?
|
178
|
+
path = watched_file.path
|
179
|
+
begin
|
180
|
+
stat = watched_file.restat
|
181
|
+
watched_file.activate
|
182
|
+
# don't do create again
|
183
|
+
next if watched_file.state_history_any?(:closed, :ignored)
|
184
|
+
# if the file can't be opened during the yield
|
185
|
+
# its state is set back to watched
|
186
|
+
sym = watched_file.initial? ? :create_initial : :create
|
187
|
+
yield(sym, watched_file)
|
188
|
+
rescue Errno::ENOENT
|
189
|
+
# file has gone away or we can't read it anymore.
|
190
|
+
file_deletable << path
|
191
|
+
watched_file.unwatch
|
192
|
+
yield(:delete, watched_file)
|
193
|
+
next
|
194
|
+
@logger.debug? && @logger.debug("each: closed: stat failed: #{path}: (#{$!}), deleting from @files")
|
195
|
+
rescue => e
|
196
|
+
@logger.error("each: watched?: #{path}: (#{e.inspect})")
|
197
|
+
end
|
181
198
|
end
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
199
|
+
else
|
200
|
+
now = Time.now.to_i
|
201
|
+
if (now - @lastwarn_max_files) > MAX_FILES_WARN_INTERVAL
|
202
|
+
waiting = @files.size - @max_active
|
203
|
+
specific = if @close_older.nil?
|
204
|
+
", try setting close_older. There are #{waiting} unopened files"
|
205
|
+
else
|
206
|
+
", files yet to open: #{waiting}"
|
207
|
+
end
|
208
|
+
@logger.warn(@max_warn_msg + specific)
|
209
|
+
@lastwarn_max_files = now
|
191
210
|
end
|
192
|
-
@logger.warn(@max_warn_msg + specific)
|
193
|
-
@lastwarn_max_files = now
|
194
211
|
end
|
195
|
-
end
|
196
212
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
213
|
+
return if quit?
|
214
|
+
|
215
|
+
# wf.active means the actual files were opened
|
216
|
+
# and have been read once - unless they were empty at the time
|
217
|
+
watched_files.select {|wf| wf.active? }.each do |watched_file|
|
218
|
+
path = watched_file.path
|
219
|
+
break if quit?
|
220
|
+
begin
|
221
|
+
stat = watched_file.restat
|
222
|
+
rescue Errno::ENOENT
|
223
|
+
# file has gone away or we can't read it anymore.
|
224
|
+
file_deletable << path
|
225
|
+
@logger.debug? && @logger.debug("each: active: stat failed: #{path}: (#{$!}), deleting from @files")
|
226
|
+
watched_file.unwatch
|
227
|
+
yield(:delete, watched_file)
|
228
|
+
next
|
229
|
+
rescue => e
|
230
|
+
@logger.error("each: active?: #{path}: (#{e.inspect})")
|
231
|
+
next
|
232
|
+
end
|
214
233
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
234
|
+
if watched_file.file_closable?
|
235
|
+
@logger.debug? && @logger.debug("each: active: file expired: #{path}")
|
236
|
+
yield(:timeout, watched_file)
|
237
|
+
watched_file.close
|
238
|
+
next
|
239
|
+
end
|
221
240
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
241
|
+
_inode = inode(path,stat)
|
242
|
+
read_thus_far = watched_file.bytes_read
|
243
|
+
# we don't update the size here, its updated when we actually read
|
244
|
+
if watched_file.inode_changed?(_inode)
|
245
|
+
@logger.debug? && @logger.debug("each: new inode: #{path}: old inode was #{watched_file.inode.inspect}, new is #{_inode.inspect}")
|
246
|
+
watched_file.update_inode(_inode)
|
247
|
+
yield(:delete, watched_file)
|
248
|
+
yield(:create, watched_file)
|
249
|
+
elsif stat.size < read_thus_far
|
250
|
+
@logger.debug? && @logger.debug("each: file rolled: #{path}: new size is #{stat.size}, old size #{read_thus_far}")
|
251
|
+
yield(:delete, watched_file)
|
252
|
+
yield(:create, watched_file)
|
253
|
+
elsif stat.size > read_thus_far
|
254
|
+
@logger.debug? && @logger.debug("each: file grew: #{path}: old size #{read_thus_far}, new size #{stat.size}")
|
255
|
+
yield(:modify, watched_file)
|
256
|
+
end
|
237
257
|
end
|
258
|
+
ensure
|
259
|
+
file_deletable.each {|f| @files.delete(f)}
|
238
260
|
end
|
239
|
-
|
240
|
-
file_deleteable.each {|f| @files.delete(f)}
|
241
261
|
end
|
242
262
|
end # def each
|
243
263
|
|
@@ -258,7 +278,7 @@ module FileWatch
|
|
258
278
|
reset_quit
|
259
279
|
while !quit?
|
260
280
|
each(&block)
|
261
|
-
|
281
|
+
break if quit?
|
262
282
|
glob += 1
|
263
283
|
if glob == discover_interval
|
264
284
|
discover
|
metadata
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Sissel
|
8
8
|
- Pete Fritchman
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
+
name: stud
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - '>='
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '0'
|
20
|
-
name: stud
|
21
|
-
prerelease: false
|
22
21
|
type: :development
|
22
|
+
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
-
description: Watch files and directories in ruby. Also supports tailing and glob file
|
28
|
+
description: Watch files and directories in ruby. Also supports tailing and glob file
|
29
|
+
patterns.
|
29
30
|
email:
|
30
31
|
- jls@semicomplete.com
|
31
32
|
- petef@databits.net
|
@@ -34,8 +35,6 @@ executables:
|
|
34
35
|
extensions: []
|
35
36
|
extra_rdoc_files: []
|
36
37
|
files:
|
37
|
-
- bin/globtail
|
38
|
-
- lib/JRubyFileExtension.jar
|
39
38
|
- lib/filewatch/buftok.rb
|
40
39
|
- lib/filewatch/helper.rb
|
41
40
|
- lib/filewatch/observing_tail.rb
|
@@ -45,9 +44,10 @@ files:
|
|
45
44
|
- lib/filewatch/watched_file.rb
|
46
45
|
- lib/filewatch/winhelper.rb
|
47
46
|
- lib/filewatch/yielding_tail.rb
|
47
|
+
- lib/JRubyFileExtension.jar
|
48
48
|
- test/filewatch/tail.rb
|
49
|
-
- test/globtail/Makefile
|
50
49
|
- test/globtail/framework.sh
|
50
|
+
- test/globtail/Makefile
|
51
51
|
- test/globtail/test1.data
|
52
52
|
- test/globtail/test1.sh
|
53
53
|
- test/globtail/test10.data
|
@@ -68,10 +68,11 @@ files:
|
|
68
68
|
- test/globtail/test8.sh
|
69
69
|
- test/globtail/test9.data
|
70
70
|
- test/globtail/test9.sh
|
71
|
+
- bin/globtail
|
71
72
|
homepage: https://github.com/jordansissel/ruby-filewatch
|
72
73
|
licenses: []
|
73
74
|
metadata: {}
|
74
|
-
post_install_message:
|
75
|
+
post_install_message:
|
75
76
|
rdoc_options: []
|
76
77
|
require_paths:
|
77
78
|
- lib
|
@@ -87,9 +88,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: '0'
|
89
90
|
requirements: []
|
90
|
-
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
92
|
-
signing_key:
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.14
|
93
|
+
signing_key:
|
93
94
|
specification_version: 4
|
94
95
|
summary: filewatch - file watching for ruby
|
95
96
|
test_files: []
|