From e49bd57279b72cf517853aec369e341fa3442d60 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 7 Jul 2020 21:09:13 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/models/merge_request_diff.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index ba51f2bd822..eb5250d5cf6 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -493,6 +493,8 @@ class MergeRequestDiff < ApplicationRecord self.stored_externally = true rows + ensure + tempfile&.unlink end def create_merge_request_diff_files(rows) @@ -503,19 +505,17 @@ class MergeRequestDiff < ApplicationRecord end def build_external_diff_tempfile(rows) - pos = 0 + Tempfile.open(external_diff.filename) do |file| + rows.each do |row| + data = row.delete(:diff) + row[:external_diff_offset] = file.pos + row[:external_diff_size] = data.bytesize - segments = rows.map do |row| - segment = row.delete(:diff) - - row[:external_diff_offset] = pos - row[:external_diff_size] = segment.bytesize - pos += segment.bytesize + file.write(data) + end - segment + file end - - CarrierWaveStringFile.new(segments.join(''), external_diff.filename) end def build_merge_request_diff_files(diffs) -- cgit v1.2.1