summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-24 20:20:20 +0900
committerShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-24 20:20:20 +0900
commitcf4ab10d71ea03c83fad22abf70dac21bbf73e72 (patch)
tree0fa21cb4b1915e443656b700c0978f8623daf844
parenta16387486ae6db94b1aa49310cfc67642b68f23c (diff)
downloadgitlab-ce-cf4ab10d71ea03c83fad22abf70dac21bbf73e72.tar.gz
Adopt ayufan script
-rw-r--r--lib/gitlab/ci/trace/stream.rb25
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