ffilewatch 0.6.1 → 0.6.2
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.rb +13 -6
- data/lib/filewatch/watch.rb +17 -11
- metadata +1 -2
- data/bin/globtail +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 829dcc5451842718057f3e2916b96d65616220ff
|
4
|
+
data.tar.gz: ddee5a1d1e691e0b308b210ff6e04f4dbeafb35d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 361b21094d3e94ca3f052ef0605141cd0e66e422d2c56e2d320db9d298f736136f74a3a88bcdecf1fa9f32aba61f5ffb4ac8d82c3ddacb34d1a71036993592ab
|
7
|
+
data.tar.gz: fb95934e8663c2f8eb4cd12d9a67c877a461d1fecee4eae0a0437d4c218327a9916294415c4cce8cc0fb64769a5854a93f1354375165d6cb06c8c59e92e77a99
|
data/lib/filewatch/tail.rb
CHANGED
@@ -76,7 +76,7 @@ module FileWatch
|
|
76
76
|
@opts[:discover_interval]) do |event, path|
|
77
77
|
case event
|
78
78
|
when :create, :create_initial
|
79
|
-
if
|
79
|
+
if !@files[path].nil?
|
80
80
|
@logger.debug("#{event} for #{path}: already exists in @files")
|
81
81
|
next
|
82
82
|
end
|
@@ -94,12 +94,16 @@ module FileWatch
|
|
94
94
|
end
|
95
95
|
when :delete
|
96
96
|
@logger.debug(":delete for #{path}, deleted from @files")
|
97
|
-
|
98
|
-
@files[path].
|
99
|
-
|
97
|
+
# if File::exist?(path) # Rotated
|
98
|
+
# if @files[path].nil?
|
99
|
+
# _open_file(path, event)
|
100
|
+
# end
|
101
|
+
# _read_file(path, &block)
|
102
|
+
# end
|
103
|
+
@files.delete(path).close rescue nil
|
100
104
|
@statcache.delete(path)
|
101
105
|
when :noupdate
|
102
|
-
@logger.debug(":noupdate for #{path}, from @files")
|
106
|
+
# @logger.debug(":noupdate for #{path}, from @files")
|
103
107
|
_sincedb_write_if_pending # will check to see if sincedb_write requests are pending
|
104
108
|
else
|
105
109
|
@logger.warn("unknown event type #{event} for #{path}")
|
@@ -189,6 +193,9 @@ module FileWatch
|
|
189
193
|
end
|
190
194
|
|
191
195
|
@sincedb[@statcache[path]] = @files[path].pos
|
196
|
+
rescue NoMethodError
|
197
|
+
@logger.warn("_read_file: file deleted while reading %s" % path)
|
198
|
+
break
|
192
199
|
rescue Errno::EWOULDBLOCK, Errno::EINTR, EOFError
|
193
200
|
break
|
194
201
|
end
|
@@ -315,7 +322,7 @@ module FileWatch
|
|
315
322
|
next if @locked[path]
|
316
323
|
next if @files[path].nil?
|
317
324
|
@logger.debug(":evict for #{path}, deleted from @files")
|
318
|
-
@files.delete(path).close
|
325
|
+
@files.delete(path).close rescue nil
|
319
326
|
@statcache.delete(path)
|
320
327
|
@changed.delete(path)
|
321
328
|
@locked.delete(path)
|
data/lib/filewatch/watch.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "logger"
|
2
|
+
require "pathname"
|
2
3
|
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
3
4
|
require "filewatch/winhelper"
|
4
5
|
end
|
@@ -53,9 +54,9 @@ module FileWatch
|
|
53
54
|
@files.keys.each do |path|
|
54
55
|
if ! @files[path][:create_sent]
|
55
56
|
if @files[path][:initial]
|
56
|
-
yield(:create_initial, path)
|
57
|
+
yield(:create_initial, real(path))
|
57
58
|
else
|
58
|
-
yield(:create, path)
|
59
|
+
yield(:create, real(path))
|
59
60
|
end
|
60
61
|
@files[path][:create_sent] = true
|
61
62
|
end
|
@@ -68,7 +69,7 @@ module FileWatch
|
|
68
69
|
# file has gone away or we can't read it anymore.
|
69
70
|
@files.delete(path)
|
70
71
|
@logger.debug("#{path}: stat failed (#{$!}), deleting from @files")
|
71
|
-
yield(:delete, path)
|
72
|
+
yield(:delete, real(path))
|
72
73
|
next
|
73
74
|
end
|
74
75
|
|
@@ -81,23 +82,23 @@ module FileWatch
|
|
81
82
|
|
82
83
|
if inode != @files[path][:inode]
|
83
84
|
@logger.debug("#{path}: old inode was #{@files[path][:inode].inspect}, new is #{inode.inspect}")
|
84
|
-
yield(:delete, path)
|
85
|
-
yield(:create, path)
|
85
|
+
yield(:delete, real(path))
|
86
|
+
yield(:create, real(path))
|
86
87
|
elsif stat.size < @files[path][:size]
|
87
88
|
@logger.debug("#{path}: file rolled, new size is #{stat.size}, old size #{@files[path][:size]}")
|
88
|
-
yield(:delete, path)
|
89
|
-
yield(:create, path)
|
89
|
+
yield(:delete, real(path))
|
90
|
+
yield(:create, real(path))
|
90
91
|
elsif stat.size > @files[path][:size]
|
91
92
|
@logger.debug("#{path}: file grew, old size #{@files[path][:size]}, new size #{stat.size}")
|
92
|
-
yield(:modify, path)
|
93
|
+
yield(:modify, real(path))
|
93
94
|
else
|
94
95
|
# since there is no update, we should pass control back in case the caller needs to do any work
|
95
96
|
# otherwise, they can ONLY do other work when a file is created or modified
|
96
|
-
@logger.debug("#{path}: nothing to update")
|
97
|
-
yield(:noupdate, path)
|
97
|
+
# @logger.debug("#{path}: nothing to update")
|
98
|
+
yield(:noupdate, real(path))
|
98
99
|
end
|
99
100
|
|
100
|
-
@files[path][:size]
|
101
|
+
@files[path][:size] = stat.size
|
101
102
|
@files[path][:inode] = inode
|
102
103
|
end # @files.keys.each
|
103
104
|
end # def each
|
@@ -126,6 +127,11 @@ module FileWatch
|
|
126
127
|
end
|
127
128
|
end # def subscribe
|
128
129
|
|
130
|
+
private
|
131
|
+
def real path
|
132
|
+
Pathname.new(path).realpath.to_s rescue path
|
133
|
+
end
|
134
|
+
|
129
135
|
private
|
130
136
|
def _discover_file(path, initial=false)
|
131
137
|
globbed_dirs = Dir.glob(path)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffilewatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Sissel
|
@@ -34,7 +34,6 @@ executables: []
|
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
-
- bin/globtail
|
38
37
|
- lib/JRubyFileExtension.jar
|
39
38
|
- lib/filewatch/tail.rb
|
40
39
|
- lib/filewatch/watch.rb
|
data/bin/globtail
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "filewatch/tail"
|
4
|
-
require "optparse"
|
5
|
-
|
6
|
-
progname = File.basename($0)
|
7
|
-
|
8
|
-
config = {
|
9
|
-
:verbose => false,
|
10
|
-
}
|
11
|
-
|
12
|
-
opts = OptionParser.new do |opts|
|
13
|
-
opts.banner = "#{progname} [-v] [-s path] [-i interval] [-x glob] path/glob ..."
|
14
|
-
|
15
|
-
opts.on("-v", "--verbose", "Enable verbose/debug output") do
|
16
|
-
config[:verbose] = true
|
17
|
-
end
|
18
|
-
|
19
|
-
opts.on("-x", "--exclude PATH", String, "path to exclude from watching") do |path|
|
20
|
-
config[:exclude] ||= []
|
21
|
-
config[:exclude] << path
|
22
|
-
end
|
23
|
-
|
24
|
-
opts.on("-s", "--sincedb PATH", String, "Sincedb path") do |path|
|
25
|
-
config[:sincedb_path] = path
|
26
|
-
end
|
27
|
-
|
28
|
-
opts.on("-i", "--interval SECONDS", Integer,
|
29
|
-
"Sincedb write interval") do |path|
|
30
|
-
config[:sincedb_write_interval] = path
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
begin
|
35
|
-
opts.order!
|
36
|
-
rescue OptionParser::InvalidOption
|
37
|
-
$stderr.puts "#{progname}: #{$!}"
|
38
|
-
$stderr.puts opts.usage
|
39
|
-
end
|
40
|
-
|
41
|
-
logger = Logger.new(STDERR)
|
42
|
-
logger.progname = progname
|
43
|
-
logger.level = config[:verbose] ? Logger::DEBUG : Logger::INFO
|
44
|
-
config[:logger] = logger
|
45
|
-
|
46
|
-
tail = FileWatch::Tail.new(config)
|
47
|
-
|
48
|
-
ARGV.each { |path| tail.tail(path) }
|
49
|
-
|
50
|
-
Signal.trap("EXIT") { tail.sincedb_write("globtail exiting") }
|
51
|
-
|
52
|
-
$stdout.sync = true
|
53
|
-
tail.subscribe do |path, line|
|
54
|
-
puts "#{path}: #{line}"
|
55
|
-
end
|