summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/files.rb4
-rw-r--r--lib/gitlab/satellite/files/edit_file_action.rb5
-rw-r--r--lib/gitlab/satellite/files/file_action.rb8
-rw-r--r--lib/gitlab/satellite/files/new_file_action.rb4
4 files changed, 15 insertions, 6 deletions
diff --git a/lib/api/files.rb b/lib/api/files.rb
index 5e2a68809e5..213604915a6 100644
--- a/lib/api/files.rb
+++ b/lib/api/files.rb
@@ -18,7 +18,7 @@ module API
#
post ":id/repository/files" do
required_attributes! [:file_path, :branch_name, :content, :commit_message]
- attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message]
+ attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message, :encoding]
branch_name = attrs.delete(:branch_name)
file_path = attrs.delete(:file_path)
result = ::Files::CreateService.new(user_project, current_user, attrs, branch_name, file_path).execute
@@ -48,7 +48,7 @@ module API
#
put ":id/repository/files" do
required_attributes! [:file_path, :branch_name, :content, :commit_message]
- attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message]
+ attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message, :encoding]
branch_name = attrs.delete(:branch_name)
file_path = attrs.delete(:file_path)
result = ::Files::UpdateService.new(user_project, current_user, attrs, branch_name, file_path).execute
diff --git a/lib/gitlab/satellite/files/edit_file_action.rb b/lib/gitlab/satellite/files/edit_file_action.rb
index f410ecb7984..cbdf70f7d12 100644
--- a/lib/gitlab/satellite/files/edit_file_action.rb
+++ b/lib/gitlab/satellite/files/edit_file_action.rb
@@ -10,7 +10,7 @@ module Gitlab
# Returns false if committing the change fails
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
- def commit!(content, commit_message)
+ def commit!(content, commit_message, encoding)
in_locked_and_timed_satellite do |repo|
prepare_satellite!(repo)
@@ -26,7 +26,8 @@ module Gitlab
return false
end
- File.open(file_path_in_satellite, 'w') { |f| f.write(content) }
+ # Write file
+ write_file(file_path_in_satellite, content, encoding)
# commit the changes
# will raise CommandFailed when commit fails
diff --git a/lib/gitlab/satellite/files/file_action.rb b/lib/gitlab/satellite/files/file_action.rb
index 0f7afde647d..7701a6d5d60 100644
--- a/lib/gitlab/satellite/files/file_action.rb
+++ b/lib/gitlab/satellite/files/file_action.rb
@@ -12,6 +12,14 @@ module Gitlab
def safe_path?(path)
File.absolute_path(path) == path
end
+
+ def write_file(abs_file_path, content, file_encoding = 'text')
+ if file_encoding == 'base64'
+ File.open(abs_file_path, 'wb') { |f| f.write(Base64.decode64(content)) }
+ else
+ File.open(abs_file_path, 'w') { |f| f.write(content) }
+ end
+ end
end
end
end
diff --git a/lib/gitlab/satellite/files/new_file_action.rb b/lib/gitlab/satellite/files/new_file_action.rb
index 57d101ff535..15e9b7a6f77 100644
--- a/lib/gitlab/satellite/files/new_file_action.rb
+++ b/lib/gitlab/satellite/files/new_file_action.rb
@@ -9,7 +9,7 @@ module Gitlab
# Returns false if committing the change fails
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
- def commit!(content, commit_message)
+ def commit!(content, commit_message, encoding)
in_locked_and_timed_satellite do |repo|
prepare_satellite!(repo)
@@ -29,7 +29,7 @@ module Gitlab
FileUtils.mkdir_p(dir_name_in_satellite)
# Write file
- File.open(file_path_in_satellite, 'w') { |f| f.write(content) }
+ write_file(file_path_in_satellite, content, encoding)
# add new file
repo.add(file_path_in_satellite)