Permalink
Browse files

Merge pull request #100 from cabeca/better-encode

Better encode
  • Loading branch information...
2 parents 38b6a2a + 3547111 commit ad65ca37284b62f16180d119fc887d393494fb18 @randx randx committed Feb 26, 2013
Showing with 11 additions and 20 deletions.
  1. +5 −17 app/models/build.rb
  2. +0 −1 config/initializers/encoding_detection.rb
  3. +2 −0 lib/gitlab_ci/encode.rb
  4. +4 −2 lib/runner.rb
View
@@ -81,8 +81,7 @@ def commit
def write_trace(trace)
self.reload
- sanitized_output = sanitize_build_output(trace)
- update_attributes(trace: sanitized_output)
+ update_attributes(trace: trace)
end
def short_before_sha
@@ -94,31 +93,20 @@ def short_sha
end
def trace_html
- if trace.present?
- Ansi2html::convert(compose_output)
- else
- ''
- end
- end
-
- def sanitize_build_output(output)
- GitlabCi::Encode.encode!(output)
+ html = Ansi2html::convert(compose_output) if trace.present?
+ html ||= ''
end
def read_tmp_file
- content = if tmp_file && File.readable?(tmp_file)
- File.read(tmp_file)
- end
-
+ content = GitlabCi::Encode.encode!(File.binread(tmp_file)) if tmp_file && File.readable?(tmp_file)
content ||= ''
end
def compose_output
output = trace
if running?
- sanitized_output = sanitize_build_output(read_tmp_file)
- output << sanitized_output if sanitized_output.present?
+ output << read_tmp_file
end
output
@@ -1 +0,0 @@
-require 'charlock_holmes/string'
@@ -1,3 +1,5 @@
+require 'charlock_holmes/string'
+
module GitlabCi
module Encode
extend self
View
@@ -75,7 +75,7 @@ def command(cmd, path)
@output << "\n"
@process = ChildProcess.build(cmd)
- @tmp_file = Tempfile.new("child-output")
+ @tmp_file = Tempfile.new("child-output", binmode: true)
@process.io.stdout = @tmp_file
@process.io.stderr = @tmp_file
@process.cwd = path
@@ -99,7 +99,9 @@ def command(cmd, path)
@process.exit_code == 0
ensure
@tmp_file.rewind
- @output << @tmp_file.read
+ @output << GitlabCi::Encode.encode!(@tmp_file.read)
+ @tmp_file.close
+ @tmp_file.unlink
end
def prepare_project_cmd(path, ref)

0 comments on commit ad65ca3

Please sign in to comment.