summaryrefslogtreecommitdiff
path: root/app/uploaders
diff options
context:
space:
mode:
authorMicaƫl Bergeron <mbergeron@gitlab.com>2018-06-28 10:57:28 -0400
committerStan Hu <stanhu@gmail.com>2018-07-03 09:57:15 -0700
commitcebdd267e672c75696cd534bb89d10fda8de129f (patch)
treeae1acb12eec102ac3c7cf0769dfaaa4df29c4a1b /app/uploaders
parente61f66b3d16cf097af8fbf3072018fd7d9ec8b67 (diff)
downloadgitlab-ce-cebdd267e672c75696cd534bb89d10fda8de129f.tar.gz
add support for file copy on object storage
Diffstat (limited to 'app/uploaders')
-rw-r--r--app/uploaders/file_uploader.rb26
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)