From 1f5e809c047d9561fe03d04c51b1dc4fffd95e04 Mon Sep 17 00:00:00 2001 From: James Edwards-Jones Date: Tue, 13 Mar 2018 00:55:49 +0000 Subject: Use correct encoding with Lfs::FileTransfromer --- app/services/files/multi_service.rb | 5 +++-- app/services/lfs/file_transformer.rb | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/services/files/multi_service.rb b/app/services/files/multi_service.rb index be9c7c526a6..13a1dee4173 100644 --- a/app/services/files/multi_service.rb +++ b/app/services/files/multi_service.rb @@ -15,8 +15,9 @@ module Files def actions_after_lfs_transformation(transformer, actions) actions.map do |action| if action[:action] == 'create' - content = transformer.new_file(action[:file_path], action[:content]) - action[:content] = content + result = transformer.new_file(action[:file_path], action[:content], encoding: action[:encoding]) + action[:content] = result.content + action[:encoding] = result.encoding end action diff --git a/app/services/lfs/file_transformer.rb b/app/services/lfs/file_transformer.rb index bdb2f1bea42..69281ee3137 100644 --- a/app/services/lfs/file_transformer.rb +++ b/app/services/lfs/file_transformer.rb @@ -20,16 +20,26 @@ module Lfs @branch_name = branch_name end - def new_file(file_path, file_content) + def new_file(file_path, file_content, encoding: nil) if project.lfs_enabled? && lfs_file?(file_path) + file_content = Base64.decode64(file_content) if encoding == 'base64' lfs_pointer_file = Gitlab::Git::LfsPointerFile.new(file_content) lfs_object = create_lfs_object!(lfs_pointer_file, file_content) link_lfs_object!(lfs_object) - lfs_pointer_file.pointer + Result.new(content: lfs_pointer_file.pointer, encoding: 'text') else - file_content + Result.new(content: file_content, encoding: encoding) + end + end + + class Result + attr_reader :content, :encoding + + def initialize(content:, encoding:) + @content = content + @encoding = encoding end end -- cgit v1.2.1