diff options
author | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-05-24 20:20:20 +0900 |
---|---|---|
committer | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-05-24 20:20:20 +0900 |
commit | cf4ab10d71ea03c83fad22abf70dac21bbf73e72 (patch) | |
tree | 0fa21cb4b1915e443656b700c0978f8623daf844 /lib | |
parent | a16387486ae6db94b1aa49310cfc67642b68f23c (diff) | |
download | gitlab-ce-cf4ab10d71ea03c83fad22abf70dac21bbf73e72.tar.gz |
Adopt ayufan script
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/trace/stream.rb | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/gitlab/ci/trace/stream.rb b/lib/gitlab/ci/trace/stream.rb index 45b32e4a7f2..c5a1ddfe691 100644 --- a/lib/gitlab/ci/trace/stream.rb +++ b/lib/gitlab/ci/trace/stream.rb @@ -96,28 +96,29 @@ module Gitlab end def reverse_line - return if stream.size <= 0 - - pos = 0 - max = stream.size + stream.seek(0, IO::SEEK_END) debris = '' - while (read_size = calc_read_size(pos, max)) > 0 - pos += read_size - stream.seek(-pos, IO::SEEK_END) - buf = stream.read(read_size) + debris + while !(buf = read_backward(BUFFER_SIZE)).empty? + buf += debris debris, *lines = buf.each_line.to_a lines.reverse_each do |line| yield(line.force_encoding('UTF-8')) end end - yield(debris.force_encoding('UTF-8')) + yield(debris.force_encoding('UTF-8')) if !(debris).empty? end - def calc_read_size(pos, max) - remain = max - pos - (remain > BUFFER_SIZE) ? BUFFER_SIZE : remain + def read_backward(length) + cur_offset = stream.tell + start = cur_offset - length + start = 0 if start < 0 + + stream.seek(start, IO::SEEK_SET) + stream.read(cur_offset - start).tap do + stream.seek(start, IO::SEEK_SET) + end end end end |