diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2019-06-14 20:01:53 +0200 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2019-06-14 20:01:53 +0200 |
commit | 154f9aded9bf5ecd21de0ba97b1e3d8674ab71fb (patch) | |
tree | 2eb9cac621107de87acbe3f81b4656aa2c9720a7 | |
parent | 8b200634c4909f12cd012c3197c4ffbaf50b99d5 (diff) | |
download | gitlab-ce-upload-temp-personal-snippet-upload-to-object-storage.tar.gz |
Allow uploading personal snippet temporary uploads to object storageupload-temp-personal-snippet-upload-to-object-storage
Closes https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/6827 and https://gitlab.com/gitlab-org/gitlab-ce/issues/62663
-rw-r--r-- | app/uploaders/file_mover.rb | 36 | ||||
-rw-r--r-- | app/uploaders/personal_file_uploader.rb | 1 |
2 files changed, 22 insertions, 15 deletions
diff --git a/app/uploaders/file_mover.rb b/app/uploaders/file_mover.rb index 236b7ed2b3d..997e6df70d1 100644 --- a/app/uploaders/file_mover.rb +++ b/app/uploaders/file_mover.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class FileMover + include Gitlab::Utils::StrongMemoize + attr_reader :secret, :file_name, :model, :update_field def initialize(file_path, model, update_field = :description) @@ -11,8 +13,12 @@ class FileMover end def execute + temp_file_uploader.retrieve_from_store!(file_name) + return unless valid? + uploader.retrieve_from_store!(file_name) + move if update_markdown @@ -24,14 +30,22 @@ class FileMover private def valid? - Pathname.new(temp_file_path).realpath.to_path.start_with?( - (Pathname(temp_file_uploader.root) + temp_file_uploader.base_dir).to_path - ) + if temp_file_uploader.file_storage? + Pathname.new(temp_file_path).realpath.to_path.start_with?( + (Pathname(temp_file_uploader.root) + temp_file_uploader.base_dir).to_path + ) + else + temp_file_uploader.exists? + end end def move - FileUtils.mkdir_p(File.dirname(file_path)) - FileUtils.move(temp_file_path, file_path) + if temp_file_uploader.file_storage? + FileUtils.mkdir_p(File.dirname(file_path)) + FileUtils.move(temp_file_path, file_path) + else + uploader.copy_file(temp_file_uploader.file) + end end def update_markdown @@ -44,19 +58,11 @@ class FileMover end def temp_file_path - return @temp_file_path if @temp_file_path - - temp_file_uploader.retrieve_from_store!(file_name) - - @temp_file_path = temp_file_uploader.file.path + strong_memoize(:temp_file_path) { temp_file_uploader.file.path } end def file_path - return @file_path if @file_path - - uploader.retrieve_from_store!(file_name) - - @file_path = uploader.file.path + strong_memoize(:file_path) { uploader.file.path } end def uploader diff --git a/app/uploaders/personal_file_uploader.rb b/app/uploaders/personal_file_uploader.rb index b43162f0935..0fc6f41bafb 100644 --- a/app/uploaders/personal_file_uploader.rb +++ b/app/uploaders/personal_file_uploader.rb @@ -21,6 +21,7 @@ class PersonalFileUploader < FileUploader end def object_store + return Store::REMOTE if self.class.object_store_enabled? return Store::LOCAL unless model super |