diff options
author | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-05-05 21:16:39 +0300 |
---|---|---|
committer | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-05-24 14:10:14 +0300 |
commit | 6018afa89fc34b0ea9ba691e3690a9837fadc122 (patch) | |
tree | 57d8eb53827e2feb2455ee31f6bfe7e7a5dbc7fd /lib/gitlab/ci | |
parent | a1cddf051e6a4a2e0cb3a20efb9f323328fa4bce (diff) |
Add reverse_line
Diffstat (limited to 'lib/gitlab/ci')
-rw-r--r-- | lib/gitlab/ci/trace/stream.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/gitlab/ci/trace/stream.rb b/lib/gitlab/ci/trace/stream.rb index fa462cbe095..be8e40af016 100644 --- a/lib/gitlab/ci/trace/stream.rb +++ b/lib/gitlab/ci/trace/stream.rb @@ -73,7 +73,7 @@ module Gitlab match = "" - stream.each_line do |line| + reverse_line do |line| matches = line.scan(regex) next unless matches.is_a?(Array) next if matches.empty? @@ -115,6 +115,26 @@ module Gitlab chunks.join.lines.last(last_lines).join end + + def reverse_line + pos = 0 + max = stream.size + + while true + pos += BUFFER_SIZE + + buf = + if pos <= max + stream.seek(-pos, IO::SEEK_END) + stream.read(BUFFER_SIZE) + else # Reached the head, read only left + stream.seek(0) + stream.read(BUFFER_SIZE - (pos - max)) + end + + yield(buf) + end + end end end end |