filewatch 0.8.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59ac6ba9efca68da9ea0b3342e87deab3635f53c
4
- data.tar.gz: 5a71f0673de75e1444584b01c0dcfe56e039d2ce
3
+ metadata.gz: e80ef8ef31b018ae2e8bcca3794c6389efbe9668
4
+ data.tar.gz: bf76dc26caa7715951a657769ad64a9bda8b5ca6
5
5
  SHA512:
6
- metadata.gz: 366003c080654805fa4da59a6ef354a25cb0a8495090d668ad0dd8ae628e7bf7438b5d0894938925bed8d8e2b08a6dae3671a0772480d94d210039273aaa7e01
7
- data.tar.gz: d05f46ef57830653fbd19c3eef0d4e49fd4137f5604d0296df1991fc64ae0b6b74c926a7e2796bf528d4c55d1571f8a9b190115b88571110027bb16ebe6fe8fb
6
+ metadata.gz: 63156fc561b37940e580a9bcbee7d2649f9b1ba24f8c16cb58830a9850baf2734c7f9ef6dbd0ba2cd4d5efcabf8d26c6f0f69dffca36ce7b0b388b6c9ea5f4d8
7
+ data.tar.gz: a0b76e79c2393bb8d05ceb6a18378e750c7eec25a7c4df61da066bacd0cc1f6b2f2c0e1287d629768a846ba4bb32dd9c7c56727b098a9cf2a49de5c6dc7dbfac
@@ -64,6 +64,8 @@ module FileWatch
64
64
  @logger.warn("unknown event type #{event} for #{path}")
65
65
  end
66
66
  end # @watch.subscribe
67
+ # when watch.subscribe ends - its because we got quit
68
+ _sincedb_write
67
69
  end # def subscribe
68
70
 
69
71
  private
@@ -11,13 +11,11 @@ module FileWatch
11
11
  attr_writer :target
12
12
 
13
13
  def self.new_observing(opts = {})
14
- new.tap do |instance|
15
- instance.target = ObservingTail.new(opts)
16
- end
14
+ new({}, ObservingTail.new(opts))
17
15
  end
18
16
 
19
- def initialize(opts = {})
20
- @target = YieldingTail.new(opts)
17
+ def initialize(opts = {}, target = YieldingTail.new(opts))
18
+ @target = target
21
19
  end
22
20
  end
23
21
  end
@@ -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
@@ -117,127 +117,147 @@ module FileWatch
117
117
  def each(&block)
118
118
  synchronized do
119
119
  return if @files.empty?
120
-
121
- file_deleteable = []
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
- begin
129
- stat = watched_file.restat
130
- if watched_file.size_changed? || watched_file.inode_changed?(inode(path,stat))
131
- # if the closed file changed, move it to the watched state
132
- # not to active state because we want to use MAX_OPEN_FILES throttling.
133
- watched_file.watch
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
- end
143
-
144
- # look at the ignored to see if its changed
145
- watched_files.select {|wf| wf.ignored? }.each do |watched_file|
146
- path = watched_file.path
147
- begin
148
- stat = watched_file.restat
149
- if watched_file.size_changed? || watched_file.inode_changed?(inode(path,stat))
150
- # if the ignored file changed, move it to the watched state
151
- # not to active state because we want to use MAX_OPEN_FILES throttling.
152
- # this file has not been yielded to the block yet
153
- # but we must have the tail to start from the end, so when the file
154
- # was first ignored we updated the bytes_read to the stat.size at that time.
155
- # by adding this to the sincedb so that the subsequent modify
156
- # event can detect the change
157
- watched_file.watch
158
- yield(:unignore, watched_file)
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
- # Send any creates.
170
- if (to_take = @max_active - watched_files.count{|wf| wf.active?}) > 0
171
- watched_files.select {|wf| wf.watched? }.take(to_take).each do |watched_file|
172
- watched_file.activate
173
- # don't do create again
174
- next if watched_file.state_history_any?(:closed, :ignored)
175
- # if the file can't be opened during the yield
176
- # its state is set back to watched
177
- if watched_file.initial?
178
- yield(:create_initial, watched_file)
179
- else
180
- yield(:create, watched_file)
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
- end
183
- else
184
- now = Time.now.to_i
185
- if (now - @lastwarn_max_files) > MAX_FILES_WARN_INTERVAL
186
- waiting = @files.size - @max_active
187
- specific = if @close_older.nil?
188
- ", try setting close_older. There are #{waiting} unopened files"
189
- else
190
- ", files yet to open: #{waiting}"
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
- # wf.active means the actual files were opened
198
- # and have been read once - unless they were empty at the time
199
- watched_files.select {|wf| wf.active? }.each do |watched_file|
200
- path = watched_file.path
201
- begin
202
- stat = watched_file.restat
203
- rescue Errno::ENOENT
204
- # file has gone away or we can't read it anymore.
205
- file_deleteable << path
206
- @logger.debug? && @logger.debug("each: active: stat failed: #{path}: (#{$!}), deleting from @files")
207
- watched_file.unwatch
208
- yield(:delete, watched_file)
209
- next
210
- rescue => e
211
- @logger.debug? && @logger.debug("each: active: stat failed: #{path}: (#{e.inspect})")
212
- next
213
- end
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
- if watched_file.file_closable?
216
- @logger.debug? && @logger.debug("each: active: file expired: #{path}")
217
- yield(:timeout, watched_file)
218
- watched_file.close
219
- next
220
- end
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
- _inode = inode(path,stat)
223
- read_thus_far = watched_file.bytes_read
224
- # we don't update the size here, its updated when we actually read
225
- if watched_file.inode_changed?(_inode)
226
- @logger.debug? && @logger.debug("each: new inode: #{path}: old inode was #{watched_file.inode.inspect}, new is #{_inode.inspect}")
227
- watched_file.update_inode(_inode)
228
- yield(:delete, watched_file)
229
- yield(:create, watched_file)
230
- elsif stat.size < read_thus_far
231
- @logger.debug? && @logger.debug("each: file rolled: #{path}: new size is #{stat.size}, old size #{read_thus_far}")
232
- yield(:delete, watched_file)
233
- yield(:create, watched_file)
234
- elsif stat.size > read_thus_far
235
- @logger.debug? && @logger.debug("each: file grew: #{path}: old size #{read_thus_far}, new size #{stat.size}")
236
- yield(:modify, watched_file)
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
@@ -47,6 +47,8 @@ module FileWatch
47
47
  @logger.warn("unknown event type #{event} for #{path}")
48
48
  end
49
49
  end # @watch.subscribe
50
+ # when watch.subscribe ends - its because we got quit
51
+ _sincedb_write
50
52
  end # def subscribe
51
53
 
52
54
  private
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.0
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-01-27 00:00:00.000000000 Z
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 patterns.
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.4.8
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: []