diff options
author | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-05-06 03:16:39 +0900 |
---|---|---|
committer | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-05-24 20:10:14 +0900 |
commit | 6018afa89fc34b0ea9ba691e3690a9837fadc122 (patch) | |
tree | 57d8eb53827e2feb2455ee31f6bfe7e7a5dbc7fd /lib/gitlab/ci | |
parent | a1cddf051e6a4a2e0cb3a20efb9f323328fa4bce (diff) | |
download | gitlab-ce-6018afa89fc34b0ea9ba691e3690a9837fadc122.tar.gz |
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 |