filewatch 0.6.8 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filewatch/tail_base.rb +4 -4
- data/lib/filewatch/watch.rb +26 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 942a2b016e43afadaa980bf4964646a425ed763a
|
4
|
+
data.tar.gz: eed10c3d4d6368803121747a1d9777bc01df7f5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc6dc3c1a2ad58f9e5e34d2d60a73d44c1f6727e698ee13ef6d5dbc72c9d215488577a121dd084c3e6316b435d3f5c98effe631de90d31dd9b3ae4405eebb71a
|
7
|
+
data.tar.gz: 8212663fd9cfd801ecf88f214c2d30356c20cc3f29a7af18b0ec1794eca87adbd72e330e7fac744ad36cd86dd6826b90c7cbe83ccfa3af4c263fe2560ee17400
|
data/lib/filewatch/tail_base.rb
CHANGED
@@ -45,7 +45,6 @@ module FileWatch
|
|
45
45
|
:discover_interval => 5,
|
46
46
|
:exclude => [],
|
47
47
|
:start_new_files_at => :end,
|
48
|
-
# :ignore_after => 24 * 60 * 60,
|
49
48
|
:delimiter => "\n"
|
50
49
|
}.merge(opts)
|
51
50
|
if !@opts.include?(:sincedb_path)
|
@@ -56,7 +55,8 @@ module FileWatch
|
|
56
55
|
raise NoSinceDBPathGiven.new("No HOME or SINCEDB_PATH set in environment. I need one of these set so I can keep track of the files I am following.")
|
57
56
|
end
|
58
57
|
@watch.exclude(@opts[:exclude])
|
59
|
-
@watch.
|
58
|
+
@watch.close_older = @opts[:close_older]
|
59
|
+
@watch.ignore_older = @opts[:ignore_older]
|
60
60
|
|
61
61
|
_sincedb_open
|
62
62
|
end # def initialize
|
@@ -82,11 +82,11 @@ module FileWatch
|
|
82
82
|
private
|
83
83
|
|
84
84
|
def file_expired?(stat)
|
85
|
-
return false if @opts[:
|
85
|
+
return false if @opts[:ignore_older].nil?
|
86
86
|
# (Time.now - stat.mtime) <- in jruby, this does int and float
|
87
87
|
# conversions before the subtraction and returns a float.
|
88
88
|
# so use all ints instead
|
89
|
-
(Time.now.to_i - stat.mtime.to_i) > @opts[:
|
89
|
+
(Time.now.to_i - stat.mtime.to_i) > @opts[:ignore_older]
|
90
90
|
end
|
91
91
|
|
92
92
|
def _open_file(path, event)
|
data/lib/filewatch/watch.rb
CHANGED
@@ -45,7 +45,7 @@ module FileWatch
|
|
45
45
|
def to_s() inspect; end
|
46
46
|
end
|
47
47
|
|
48
|
-
attr_accessor :logger, :
|
48
|
+
attr_accessor :logger, :close_older, :ignore_older
|
49
49
|
|
50
50
|
public
|
51
51
|
def initialize(opts={})
|
@@ -148,7 +148,7 @@ module FileWatch
|
|
148
148
|
next
|
149
149
|
end
|
150
150
|
|
151
|
-
if
|
151
|
+
if file_closable?(stat, watched_file)
|
152
152
|
if !watched_file.timeout_sent?
|
153
153
|
@logger.debug? && @logger.debug("#{path}: file expired")
|
154
154
|
yield(:timeout, path)
|
@@ -207,20 +207,24 @@ module FileWatch
|
|
207
207
|
end # def subscribe
|
208
208
|
|
209
209
|
private
|
210
|
-
def
|
211
|
-
|
210
|
+
def file_closable?(stat, watched_file)
|
211
|
+
file_can_close?(stat) && watched_file.size == stat.size
|
212
212
|
end
|
213
213
|
|
214
|
-
def
|
215
|
-
|
214
|
+
def file_ignorable?(stat)
|
215
|
+
return false unless expiry_ignore_enabled?
|
216
|
+
# (Time.now - stat.mtime) <- in jruby, this does int and float
|
217
|
+
# conversions before the subtraction and returns a float.
|
218
|
+
# so use all ints instead
|
219
|
+
(Time.now.to_i - stat.mtime.to_i) > @ignore_older
|
216
220
|
end
|
217
221
|
|
218
|
-
def
|
219
|
-
return false unless
|
222
|
+
def file_can_close?(stat)
|
223
|
+
return false unless expiry_close_enabled?
|
220
224
|
# (Time.now - stat.mtime) <- in jruby, this does int and float
|
221
225
|
# conversions before the subtraction and returns a float.
|
222
226
|
# so use all ints instead
|
223
|
-
(Time.now.to_i - stat.mtime.to_i) > @
|
227
|
+
(Time.now.to_i - stat.mtime.to_i) > @close_older
|
224
228
|
end
|
225
229
|
|
226
230
|
private
|
@@ -247,9 +251,13 @@ module FileWatch
|
|
247
251
|
# let the caller build the object in its context
|
248
252
|
watched_file = yield(file, stat)
|
249
253
|
|
250
|
-
if
|
251
|
-
msg = "_discover_file: #{file}: skipping because it was last modified more than #{@
|
254
|
+
if file_ignorable?(stat)
|
255
|
+
msg = "_discover_file: #{file}: skipping because it was last modified more than #{@ignore_older} seconds ago"
|
252
256
|
@logger.debug? && @logger.debug(msg)
|
257
|
+
# we update the size on discovery here
|
258
|
+
# so the existing contents are not read.
|
259
|
+
# because, normally, a newly discovered file will
|
260
|
+
# have a watched_file size of zero
|
253
261
|
watched_file.update(stat)
|
254
262
|
end
|
255
263
|
|
@@ -258,8 +266,13 @@ module FileWatch
|
|
258
266
|
end # def _discover_file
|
259
267
|
|
260
268
|
private
|
261
|
-
def
|
262
|
-
!@
|
269
|
+
def expiry_close_enabled?
|
270
|
+
!@close_older.nil?
|
271
|
+
end
|
272
|
+
|
273
|
+
private
|
274
|
+
def expiry_ignore_enabled?
|
275
|
+
!@ignore_older.nil?
|
263
276
|
end
|
264
277
|
|
265
278
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Sissel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-12-
|
12
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|