summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci
diff options
context:
space:
mode:
authorShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-06 03:16:39 +0900
committerShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-24 20:10:14 +0900
commit6018afa89fc34b0ea9ba691e3690a9837fadc122 (patch)
tree57d8eb53827e2feb2455ee31f6bfe7e7a5dbc7fd /lib/gitlab/ci
parenta1cddf051e6a4a2e0cb3a20efb9f323328fa4bce (diff)
downloadgitlab-ce-6018afa89fc34b0ea9ba691e3690a9837fadc122.tar.gz
Add reverse_line
Diffstat (limited to 'lib/gitlab/ci')
-rw-r--r--lib/gitlab/ci/trace/stream.rb22
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