diff options
Diffstat (limited to 'app/uploaders/file_uploader.rb')
-rw-r--r-- | app/uploaders/file_uploader.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index 36bc0a4575a..28399f1e051 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -81,6 +81,13 @@ class FileUploader < GitlabUploader apply_context!(uploader_context) end + def initialize_copy(from) + super + + @secret = self.class.generate_secret + @upload = nil # calling record_upload would delete the old upload if set + end + # enforce the usage of Hashed storage when storing to # remote store as the FileMover doesn't support OS def base_dir(store = nil) @@ -144,6 +151,25 @@ class FileUploader < GitlabUploader @secret ||= self.class.generate_secret end + # return a new uploader with a file copy on another project + def self.copy_to(uploader, to_project) + moved = uploader.dup.tap do |u| + u.model = to_project + end + + moved.copy_file(uploader.file) + moved + end + + def copy_file(file) + if file_storage? + store!(file) + else + self.file = file.copy_to(store_path) + record_upload # after_store is not triggered + end + end + private def apply_context!(uploader_context) |