eventmachine-tail 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/em/filetail.rb +19 -17
  3. data/test/test_filetail.rb +24 -7
  4. metadata +13 -17
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c548a8a257df50b5a05dd3d0f8c4de8d2e5f49dc
4
+ data.tar.gz: cac4d6fd51b4a3a0dcb743383f54fb43b7ed4cc5
5
+ SHA512:
6
+ metadata.gz: 585fd44303c0e66a3842a5adaf47cab658cd6c5921460f5f1dfcd3647c5621d173ca8e49c585d870053c6729ff54aa03182a8cd644996c6c6d7df9267dbea2c9
7
+ data.tar.gz: 39b8a7cedaad282ab7616cd791b58dd1baea8eb3eb378868aa05b7cf73cb624a9ceb3309281c82d1c3b2812b96568612d38589d332afeb433039e6b59eaf0909
@@ -35,10 +35,10 @@ EventMachine.kqueue = true if EventMachine.kqueue?
35
35
  # See also: EventMachine::FileTail#receive_data
36
36
  class EventMachine::FileTail
37
37
  # Maximum size to read at a time from a single file.
38
- CHUNKSIZE = 65536
38
+ CHUNKSIZE = 65536
39
39
 
40
40
  #MAXSLEEP = 2
41
-
41
+
42
42
  FORCE_ENCODING = !! (defined? Encoding)
43
43
 
44
44
  # The path of the file being tailed
@@ -46,7 +46,7 @@ class EventMachine::FileTail
46
46
 
47
47
  # The current file read position
48
48
  attr_reader :position
49
-
49
+
50
50
  # If this tail is closed
51
51
  attr_reader :closed
52
52
 
@@ -57,11 +57,11 @@ class EventMachine::FileTail
57
57
  # Check interval for looking for a file if we are tailing it and it has
58
58
  # gone missing.
59
59
  attr_accessor :missing_file_check_interval
60
-
60
+
61
61
  # Tail a file
62
62
  #
63
63
  # * path is a string file path to tail
64
- # * startpos is an offset to start tailing the file at. If -1, start at end of
64
+ # * startpos is an offset to start tailing the file at. If -1, start at end of
65
65
  # file.
66
66
  #
67
67
  # If you want debug messages, run ruby with '-d' or set $DEBUG
@@ -102,6 +102,8 @@ class EventMachine::FileTail
102
102
 
103
103
  EventMachine::next_tick do
104
104
  open
105
+ next unless @file
106
+
105
107
  if (startpos == -1)
106
108
  @position = @file.sysseek(0, IO::SEEK_END)
107
109
  # TODO(sissel): if we don't have inotify or kqueue, should we
@@ -116,7 +118,7 @@ class EventMachine::FileTail
116
118
  end # EventMachine::next_tick
117
119
  end # def initialize
118
120
 
119
- # This method is called when a tailed file has data read.
121
+ # This method is called when a tailed file has data read.
120
122
  #
121
123
  # * data - string data read from the file.
122
124
  #
@@ -132,7 +134,7 @@ class EventMachine::FileTail
132
134
  # @buffer.extract(data).each do |line|
133
135
  # # do something with 'line'
134
136
  # end
135
- # end
137
+ # end
136
138
  public
137
139
  def receive_data(data)
138
140
  if @handler # FileTail.new called with a block
@@ -214,13 +216,13 @@ class EventMachine::FileTail
214
216
  @file.close if @file
215
217
  end
216
218
  end # def close
217
-
219
+
218
220
  # More rubyesque way of checking if this tail is closed
219
221
  public
220
222
  def closed?
221
223
  @closed
222
224
  end
223
-
225
+
224
226
  # Watch our file.
225
227
  private
226
228
  def watch
@@ -354,19 +356,19 @@ class EventMachine::FileTail
354
356
  def read_file_metadata(&block)
355
357
  begin
356
358
  filestat = File.stat(@path)
359
+ symlink_stat = nil
360
+ symlink_target = nil
361
+
362
+ if filestat.symlink?
363
+ symlink_stat = File.lstat(@path) rescue nil
364
+ symlink_target = File.readlink(@path) rescue nil
365
+ end
357
366
  rescue Errno::ENOENT
358
367
  raise
359
368
  rescue => e
360
369
  @logger.debug("File stat on '#{@path}' failed")
361
370
  on_exception e
362
371
  end
363
- symlink_stat = nil
364
- symlink_target = nil
365
-
366
- if File.symlink?(@path)
367
- symlink_stat = File.lstat(@path) rescue nil
368
- symlink_target = File.readlink(@path) rescue nil
369
- end
370
372
 
371
373
  if block_given?
372
374
  yield filestat, symlink_stat, symlink_target
@@ -393,7 +395,7 @@ class EventMachine::FileTail
393
395
  @logger.debug "Symlink target changed. Reopening..."
394
396
  @reopen_on_eof = true
395
397
  schedule_next_read
396
- end
398
+ end
397
399
  elsif (filestat.ino != @filestat.ino or filestat.rdev != @filestat.rdev)
398
400
  @logger.debug "Inode or device changed. Reopening..."
399
401
  @logger.debug filestat
@@ -26,11 +26,11 @@ class Reader < EventMachine::FileTail
26
26
  @buffer.extract(data).each do |line|
27
27
  @lineno += 1
28
28
  expected = @data.shift
29
- @testobj.assert_equal(expected, line,
29
+ @testobj.assert_equal(expected, line,
30
30
  "Expected '#{expected}' on line #{@lineno}, but got '#{line}'")
31
31
  end # @buffer.extract
32
32
  end # def receive_data
33
-
33
+
34
34
  # This effectively tests EOF handling by requiring it to work in order
35
35
  # for the tests to pass.
36
36
  def eof
@@ -63,6 +63,23 @@ class TestFileTail < Test::Unit::TestCase
63
63
  end # EM.run
64
64
  end # def test_filetail
65
65
 
66
+ def test_filetail_close
67
+ tmp = Tempfile.new("testfiletail")
68
+ data = DATA.clone
69
+ data.each { |i| tmp.puts i }
70
+ tmp.flush
71
+
72
+ EM.run do
73
+ abort_after_timeout(2)
74
+
75
+ ft = EM::file_tail(tmp.path, Reader, -1, self)
76
+ ft.close
77
+ timer = EM::PeriodicTimer.new(0.2) do
78
+ timer.cancel and finish if ft.closed?
79
+ end
80
+ end # EM.run
81
+ end # def test_filetail_close
82
+
66
83
  def test_filetail_with_seek
67
84
  tmp = Tempfile.new("testfiletail")
68
85
  data = DATA.clone
@@ -86,7 +103,7 @@ class TestFileTail < Test::Unit::TestCase
86
103
  EM::file_tail(tmp.path) do |filetail, line|
87
104
  lineno += 1
88
105
  expected = data.shift
89
- assert_equal(expected, line,
106
+ assert_equal(expected, line,
90
107
  "Expected '#{expected}' on line #{@lineno}, but got '#{line}'")
91
108
  finish if data.length == 0
92
109
  end
@@ -120,7 +137,7 @@ class TestFileTail < Test::Unit::TestCase
120
137
  lineno += 1
121
138
  expected = data.shift
122
139
  #puts "Got #{lineno}: #{line}"
123
- assert_equal(expected, line,
140
+ assert_equal(expected, line,
124
141
  "Expected '#{expected}' on line #{lineno}, but got '#{line}'")
125
142
  finish if data.length == 0
126
143
 
@@ -176,7 +193,7 @@ class TestFileTail < Test::Unit::TestCase
176
193
  lineno += 1
177
194
  expected = data.shift
178
195
  puts "Got #{lineno}: #{line}" if $debug
179
- assert_equal(expected, line,
196
+ assert_equal(expected, line,
180
197
  "Expected '#{expected}' on line #{lineno}, but got '#{line}'")
181
198
  finish if data.length == 0
182
199
 
@@ -208,7 +225,7 @@ class TestFileTail < Test::Unit::TestCase
208
225
  File.delete(f.path)
209
226
  end
210
227
  end # def test_filetail_tracks_renames
211
-
228
+
212
229
  def test_encoding
213
230
  return if RUBY_VERSION < '1.9.0'
214
231
  tmp = Tempfile.new("testfiletail")
@@ -217,7 +234,7 @@ class TestFileTail < Test::Unit::TestCase
217
234
  abort_after_timeout(1)
218
235
 
219
236
  EM::file_tail(tmp.path) do |filetail, line|
220
- assert_equal(Encoding.default_external, line.encoding,
237
+ assert_equal(Encoding.default_external, line.encoding,
221
238
  "Expected the read data to have the encoding specified in Encoding.default_external (#{Encoding.default_external}, but was #{line.encoding})")
222
239
  finish
223
240
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-tail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
5
- prerelease:
4
+ version: 0.6.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jordan Sissel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: eventmachine
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Add file 'tail' implemented with EventMachine. Also includes a 'glob
@@ -36,42 +33,41 @@ executables:
36
33
  extensions: []
37
34
  extra_rdoc_files: []
38
35
  files:
39
- - lib/eventmachine-tail.rb
40
36
  - lib/em/globwatcher.rb
41
37
  - lib/em/filetail.rb
42
- - samples/tail.rb
38
+ - lib/eventmachine-tail.rb
39
+ - samples/glob-tail.rb
43
40
  - samples/globwatch.rb
44
41
  - samples/tail-with-block.rb
45
- - samples/glob-tail.rb
42
+ - samples/tail.rb
43
+ - test/alltests.rb
46
44
  - test/test_filetail.rb
47
45
  - test/test_glob.rb
48
46
  - test/testcase_helpers.rb
49
- - test/alltests.rb
50
47
  - bin/emtail
51
48
  - bin/rtail
52
49
  homepage: http://code.google.com/p/semicomplete/wiki/EventMachineTail
53
50
  licenses: []
51
+ metadata: {}
54
52
  post_install_message:
55
53
  rdoc_options: []
56
54
  require_paths:
57
55
  - lib
58
56
  - lib
59
57
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
58
  requirements:
62
- - - ! '>='
59
+ - - '>='
63
60
  - !ruby/object:Gem::Version
64
61
  version: '0'
65
62
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
63
  requirements:
68
- - - ! '>='
64
+ - - '>='
69
65
  - !ruby/object:Gem::Version
70
66
  version: '0'
71
67
  requirements: []
72
68
  rubyforge_project:
73
- rubygems_version: 1.8.24
69
+ rubygems_version: 2.0.14
74
70
  signing_key:
75
- specification_version: 3
71
+ specification_version: 4
76
72
  summary: eventmachine tail - a file tail implementation with glob support
77
73
  test_files: []