filewatch 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/JRubyFileExtension.jar +0 -0
- data/lib/filewatch/tail.rb +25 -20
- data/lib/filewatch/watch.rb +9 -9
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd471cc099285df704d3f28e4241871e1aa666e2
|
4
|
+
data.tar.gz: dfea4f9a717b2dc2b5d1ef1336091e7af10bf3b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adbda674e3639e946a0db108e56175a29ac10483cefe1e6ea429d4f1c8e8ca9f4434ea76f6f8db758a79d112b15152936ffddf5dea5446a939ed8be7ef7f0c09
|
7
|
+
data.tar.gz: 87608be8ee355a10e2e3962712c96254fdc971d0bab352c1a3155226d7bef63b3e9d1105c9abcff75db85a815d2f9f2789d9f19b6dfe89948c7a1015421f1145
|
Binary file
|
data/lib/filewatch/tail.rb
CHANGED
@@ -42,7 +42,8 @@ module FileWatch
|
|
42
42
|
:stat_interval => 1,
|
43
43
|
:discover_interval => 5,
|
44
44
|
:exclude => [],
|
45
|
-
:start_new_files_at => :end
|
45
|
+
:start_new_files_at => :end,
|
46
|
+
:delimiter => "\n"
|
46
47
|
}.merge(opts)
|
47
48
|
if !@opts.include?(:sincedb_path)
|
48
49
|
@opts[:sincedb_path] = File.join(ENV["HOME"], ".sincedb") if ENV.include?("HOME")
|
@@ -75,7 +76,7 @@ module FileWatch
|
|
75
76
|
case event
|
76
77
|
when :create, :create_initial
|
77
78
|
if @files.member?(path)
|
78
|
-
@logger.debug("#{event} for #{path}: already exists in @files")
|
79
|
+
@logger.debug? && @logger.debug("#{event} for #{path}: already exists in @files")
|
79
80
|
next
|
80
81
|
end
|
81
82
|
if _open_file(path, event)
|
@@ -83,7 +84,7 @@ module FileWatch
|
|
83
84
|
end
|
84
85
|
when :modify
|
85
86
|
if !@files.member?(path)
|
86
|
-
@logger.debug(":modify for #{path}, does not exist in @files")
|
87
|
+
@logger.debug? && @logger.debug(":modify for #{path}, does not exist in @files")
|
87
88
|
if _open_file(path, event)
|
88
89
|
_read_file(path, &block)
|
89
90
|
end
|
@@ -91,9 +92,11 @@ module FileWatch
|
|
91
92
|
_read_file(path, &block)
|
92
93
|
end
|
93
94
|
when :delete
|
94
|
-
@logger.debug(":delete for #{path}, deleted from @files")
|
95
|
-
|
96
|
-
|
95
|
+
@logger.debug? && @logger.debug(":delete for #{path}, deleted from @files")
|
96
|
+
if @files[path]
|
97
|
+
_read_file(path, &block)
|
98
|
+
@files[path].close
|
99
|
+
end
|
97
100
|
@files.delete(path)
|
98
101
|
@statcache.delete(path)
|
99
102
|
else
|
@@ -104,7 +107,7 @@ module FileWatch
|
|
104
107
|
|
105
108
|
private
|
106
109
|
def _open_file(path, event)
|
107
|
-
@logger.debug("_open_file: #{path}: opening")
|
110
|
+
@logger.debug? && @logger.debug("_open_file: #{path}: opening")
|
108
111
|
begin
|
109
112
|
if @iswindows && defined? JRUBY_VERSION
|
110
113
|
@files[path] = Java::RubyFileExt::getRubyFile(path)
|
@@ -120,7 +123,7 @@ module FileWatch
|
|
120
123
|
@logger.warn("failed to open #{path}: #{$!}")
|
121
124
|
@lastwarn[path] = now
|
122
125
|
else
|
123
|
-
@logger.debug("(warn supressed) failed to open #{path}: #{$!}")
|
126
|
+
@logger.debug? && @logger.debug("(warn supressed) failed to open #{path}: #{$!}")
|
124
127
|
end
|
125
128
|
@files.delete(path)
|
126
129
|
return false
|
@@ -139,28 +142,28 @@ module FileWatch
|
|
139
142
|
|
140
143
|
if @sincedb.member?(inode)
|
141
144
|
last_size = @sincedb[inode]
|
142
|
-
@logger.debug("#{path}: sincedb last value #{@sincedb[inode]}, cur size #{stat.size}")
|
145
|
+
@logger.debug? && @logger.debug("#{path}: sincedb last value #{@sincedb[inode]}, cur size #{stat.size}")
|
143
146
|
if last_size <= stat.size
|
144
|
-
@logger.debug("#{path}: sincedb: seeking to #{last_size}")
|
147
|
+
@logger.debug? && @logger.debug("#{path}: sincedb: seeking to #{last_size}")
|
145
148
|
@files[path].sysseek(last_size, IO::SEEK_SET)
|
146
149
|
else
|
147
|
-
@logger.debug("#{path}: last value size is greater than current value, starting over")
|
150
|
+
@logger.debug? && @logger.debug("#{path}: last value size is greater than current value, starting over")
|
148
151
|
@sincedb[inode] = 0
|
149
152
|
end
|
150
153
|
elsif event == :create_initial && @files[path]
|
151
154
|
# TODO(sissel): Allow starting at beginning of the file.
|
152
155
|
if @opts[:start_new_files_at] == :beginning
|
153
|
-
@logger.debug("#{path}: initial create, no sincedb, seeking to beginning of file")
|
156
|
+
@logger.debug? && @logger.debug("#{path}: initial create, no sincedb, seeking to beginning of file")
|
154
157
|
@files[path].sysseek(0, IO::SEEK_SET)
|
155
158
|
@sincedb[inode] = 0
|
156
159
|
else
|
157
160
|
# seek to end
|
158
|
-
@logger.debug("#{path}: initial create, no sincedb, seeking to end #{stat.size}")
|
161
|
+
@logger.debug? && @logger.debug("#{path}: initial create, no sincedb, seeking to end #{stat.size}")
|
159
162
|
@files[path].sysseek(stat.size, IO::SEEK_SET)
|
160
163
|
@sincedb[inode] = stat.size
|
161
164
|
end
|
162
165
|
else
|
163
|
-
@logger.debug("#{path}: staying at position 0, no sincedb")
|
166
|
+
@logger.debug? && @logger.debug("#{path}: staying at position 0, no sincedb")
|
164
167
|
end
|
165
168
|
|
166
169
|
return true
|
@@ -168,7 +171,7 @@ module FileWatch
|
|
168
171
|
|
169
172
|
private
|
170
173
|
def _read_file(path, &block)
|
171
|
-
@buffers[path] ||= FileWatch::BufferedTokenizer.new
|
174
|
+
@buffers[path] ||= FileWatch::BufferedTokenizer.new(@opts[:delimiter])
|
172
175
|
|
173
176
|
changed = false
|
174
177
|
loop do
|
@@ -189,7 +192,7 @@ module FileWatch
|
|
189
192
|
now = Time.now.to_i
|
190
193
|
delta = now - @sincedb_last_write
|
191
194
|
if delta >= @opts[:sincedb_write_interval]
|
192
|
-
@logger.debug("writing sincedb (delta since last write = #{delta})")
|
195
|
+
@logger.debug? && @logger.debug("writing sincedb (delta since last write = #{delta})")
|
193
196
|
_sincedb_write
|
194
197
|
@sincedb_last_write = now
|
195
198
|
end
|
@@ -198,7 +201,7 @@ module FileWatch
|
|
198
201
|
|
199
202
|
public
|
200
203
|
def sincedb_write(reason=nil)
|
201
|
-
@logger.debug("caller requested sincedb write (#{reason})")
|
204
|
+
@logger.debug? && @logger.debug("caller requested sincedb write (#{reason})")
|
202
205
|
_sincedb_write
|
203
206
|
end
|
204
207
|
|
@@ -208,17 +211,19 @@ module FileWatch
|
|
208
211
|
begin
|
209
212
|
db = File.open(path)
|
210
213
|
rescue
|
211
|
-
|
214
|
+
#No existing sincedb to load
|
215
|
+
@logger.debug? && @logger.debug("_sincedb_open: #{path}: #{$!}")
|
212
216
|
return
|
213
217
|
end
|
214
218
|
|
215
|
-
@logger.debug("_sincedb_open: reading from #{path}")
|
219
|
+
@logger.debug? && @logger.debug("_sincedb_open: reading from #{path}")
|
216
220
|
db.each do |line|
|
217
221
|
ino, dev_major, dev_minor, pos = line.split(" ", 4)
|
218
222
|
inode = [ino, dev_major.to_i, dev_minor.to_i]
|
219
|
-
@logger.debug("_sincedb_open: setting #{inode.inspect} to #{pos.to_i}")
|
223
|
+
@logger.debug? && @logger.debug("_sincedb_open: setting #{inode.inspect} to #{pos.to_i}")
|
220
224
|
@sincedb[inode] = pos.to_i
|
221
225
|
end
|
226
|
+
db.close
|
222
227
|
end # def _sincedb_open
|
223
228
|
|
224
229
|
private
|
data/lib/filewatch/watch.rb
CHANGED
@@ -67,7 +67,7 @@ module FileWatch
|
|
67
67
|
rescue Errno::ENOENT
|
68
68
|
# file has gone away or we can't read it anymore.
|
69
69
|
@files.delete(path)
|
70
|
-
@logger.debug("#{path}: stat failed (#{$!}), deleting from @files")
|
70
|
+
@logger.debug? && @logger.debug("#{path}: stat failed (#{$!}), deleting from @files")
|
71
71
|
yield(:delete, path)
|
72
72
|
next
|
73
73
|
end
|
@@ -80,15 +80,15 @@ module FileWatch
|
|
80
80
|
end
|
81
81
|
|
82
82
|
if inode != @files[path][:inode]
|
83
|
-
@logger.debug("#{path}: old inode was #{@files[path][:inode].inspect}, new is #{inode.inspect}")
|
83
|
+
@logger.debug? && @logger.debug("#{path}: old inode was #{@files[path][:inode].inspect}, new is #{inode.inspect}")
|
84
84
|
yield(:delete, path)
|
85
85
|
yield(:create, path)
|
86
86
|
elsif stat.size < @files[path][:size]
|
87
|
-
@logger.debug("#{path}: file rolled, new size is #{stat.size}, old size #{@files[path][:size]}")
|
87
|
+
@logger.debug? && @logger.debug("#{path}: file rolled, new size is #{stat.size}, old size #{@files[path][:size]}")
|
88
88
|
yield(:delete, path)
|
89
89
|
yield(:create, path)
|
90
90
|
elsif stat.size > @files[path][:size]
|
91
|
-
@logger.debug("#{path}: file grew, old size #{@files[path][:size]}, new size #{stat.size}")
|
91
|
+
@logger.debug? && @logger.debug("#{path}: file grew, old size #{@files[path][:size]}, new size #{stat.size}")
|
92
92
|
yield(:modify, path)
|
93
93
|
end
|
94
94
|
|
@@ -124,21 +124,21 @@ module FileWatch
|
|
124
124
|
private
|
125
125
|
def _discover_file(path, initial=false)
|
126
126
|
globbed_dirs = Dir.glob(path)
|
127
|
-
@logger.debug("_discover_file_glob: #{path}: glob is: #{globbed_dirs}")
|
127
|
+
@logger.debug? && @logger.debug("_discover_file_glob: #{path}: glob is: #{globbed_dirs}")
|
128
128
|
if globbed_dirs.empty? && File.file?(path)
|
129
129
|
globbed_dirs = [path]
|
130
|
-
@logger.debug("_discover_file_glob: #{path}: glob is: #{globbed_dirs} because glob did not work")
|
130
|
+
@logger.debug? && @logger.debug("_discover_file_glob: #{path}: glob is: #{globbed_dirs} because glob did not work")
|
131
131
|
end
|
132
132
|
globbed_dirs.each do |file|
|
133
133
|
next if @files.member?(file)
|
134
134
|
next unless File.file?(file)
|
135
135
|
|
136
|
-
@logger.debug("_discover_file: #{path}: new: #{file} (exclude is #{@exclude.inspect})")
|
136
|
+
@logger.debug? && @logger.debug("_discover_file: #{path}: new: #{file} (exclude is #{@exclude.inspect})")
|
137
137
|
|
138
138
|
skip = false
|
139
139
|
@exclude.each do |pattern|
|
140
140
|
if File.fnmatch?(pattern, File.basename(file))
|
141
|
-
@logger.debug("_discover_file: #{file}: skipping because it " +
|
141
|
+
@logger.debug? && @logger.debug("_discover_file: #{file}: skipping because it " +
|
142
142
|
"matches exclude #{pattern}")
|
143
143
|
skip = true
|
144
144
|
break
|
@@ -154,7 +154,7 @@ module FileWatch
|
|
154
154
|
}
|
155
155
|
|
156
156
|
if @iswindows
|
157
|
-
fileId = Winhelper.GetWindowsUniqueFileIdentifier(
|
157
|
+
fileId = Winhelper.GetWindowsUniqueFileIdentifier(file)
|
158
158
|
@files[file][:inode] = [fileId, stat.dev_major, stat.dev_minor]
|
159
159
|
else
|
160
160
|
@files[file][:inode] = [stat.ino.to_s, stat.dev_major, stat.dev_minor]
|
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.6.
|
4
|
+
version: 0.6.1
|
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
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Watch files and directories in ruby. Also supports tailing and glob file
|
15
15
|
patterns.
|
@@ -22,6 +22,7 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
files:
|
24
24
|
- bin/globtail
|
25
|
+
- lib/JRubyFileExtension.jar
|
25
26
|
- lib/filewatch/buftok.rb
|
26
27
|
- lib/filewatch/tail.rb
|
27
28
|
- lib/filewatch/watch.rb
|
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
70
|
version: '0'
|
70
71
|
requirements: []
|
71
72
|
rubyforge_project:
|
72
|
-
rubygems_version: 2.4.
|
73
|
+
rubygems_version: 2.4.5
|
73
74
|
signing_key:
|
74
75
|
specification_version: 4
|
75
76
|
summary: filewatch - file watching for ruby
|