Commit 21bc41c6ee9995a821900378e933e08e4e5214bc
1 parent
dba98240
Exists in
spb-stable
and in
3 other branches
Add support of base64 encoded content
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
3 changed files
with
13 additions
and
4 deletions
Show diff stats
lib/gitlab/satellite/files/edit_file_action.rb
... | ... | @@ -10,7 +10,7 @@ module Gitlab |
10 | 10 | # Returns false if committing the change fails |
11 | 11 | # Returns false if pushing from the satellite to bare repo failed or was rejected |
12 | 12 | # Returns true otherwise |
13 | - def commit!(content, commit_message) | |
13 | + def commit!(content, commit_message, encoding) | |
14 | 14 | in_locked_and_timed_satellite do |repo| |
15 | 15 | prepare_satellite!(repo) |
16 | 16 | |
... | ... | @@ -26,7 +26,8 @@ module Gitlab |
26 | 26 | return false |
27 | 27 | end |
28 | 28 | |
29 | - File.open(file_path_in_satellite, 'w') { |f| f.write(content) } | |
29 | + # Write file | |
30 | + write_file(file_path_in_satellite, content, encoding) | |
30 | 31 | |
31 | 32 | # commit the changes |
32 | 33 | # will raise CommandFailed when commit fails | ... | ... |
lib/gitlab/satellite/files/file_action.rb
... | ... | @@ -12,6 +12,14 @@ module Gitlab |
12 | 12 | def safe_path?(path) |
13 | 13 | File.absolute_path(path) == path |
14 | 14 | end |
15 | + | |
16 | + def write_file(abs_file_path, content, file_encoding = 'text') | |
17 | + if file_encoding == 'base64' | |
18 | + File.open(abs_file_path, 'wb') { |f| f.write(Base64.decode64(content)) } | |
19 | + else | |
20 | + File.open(abs_file_path, 'w') { |f| f.write(content) } | |
21 | + end | |
22 | + end | |
15 | 23 | end |
16 | 24 | end |
17 | 25 | end | ... | ... |
lib/gitlab/satellite/files/new_file_action.rb
... | ... | @@ -9,7 +9,7 @@ module Gitlab |
9 | 9 | # Returns false if committing the change fails |
10 | 10 | # Returns false if pushing from the satellite to bare repo failed or was rejected |
11 | 11 | # Returns true otherwise |
12 | - def commit!(content, commit_message) | |
12 | + def commit!(content, commit_message, encoding) | |
13 | 13 | in_locked_and_timed_satellite do |repo| |
14 | 14 | prepare_satellite!(repo) |
15 | 15 | |
... | ... | @@ -29,7 +29,7 @@ module Gitlab |
29 | 29 | FileUtils.mkdir_p(dir_name_in_satellite) |
30 | 30 | |
31 | 31 | # Write file |
32 | - File.open(file_path_in_satellite, 'w') { |f| f.write(content) } | |
32 | + write_file(file_path_in_satellite, content, encoding) | |
33 | 33 | |
34 | 34 | # add new file |
35 | 35 | repo.add(file_path_in_satellite) | ... | ... |