diff options
Diffstat (limited to 'app/uploaders')
-rw-r--r-- | app/uploaders/job_artifact_uploader.rb | 20 | ||||
-rw-r--r-- | app/uploaders/legacy_artifact_uploader.rb | 20 | ||||
-rw-r--r-- | app/uploaders/lfs_object_uploader.rb | 4 | ||||
-rw-r--r-- | app/uploaders/object_store_uploader.rb | 27 |
4 files changed, 26 insertions, 45 deletions
diff --git a/app/uploaders/job_artifact_uploader.rb b/app/uploaders/job_artifact_uploader.rb index 15dfb5a5763..a0757dbe6b2 100644 --- a/app/uploaders/job_artifact_uploader.rb +++ b/app/uploaders/job_artifact_uploader.rb @@ -1,5 +1,5 @@ -class JobArtifactUploader < GitlabUploader - storage :file +class JobArtifactUploader < ObjectStoreUploader + storage_options Gitlab.config.artifacts def self.local_store_path Gitlab.config.artifacts.path @@ -15,24 +15,8 @@ class JobArtifactUploader < GitlabUploader model.size end - def store_dir - default_local_path - end - - def cache_dir - File.join(self.class.local_store_path, 'tmp/cache') - end - - def work_dir - File.join(self.class.local_store_path, 'tmp/work') - end - private - def default_local_path - File.join(self.class.local_store_path, default_path) - end - def default_path creation_date = model.created_at.utc.strftime('%Y_%m_%d') diff --git a/app/uploaders/legacy_artifact_uploader.rb b/app/uploaders/legacy_artifact_uploader.rb index 4f7f8a63108..476a46c1754 100644 --- a/app/uploaders/legacy_artifact_uploader.rb +++ b/app/uploaders/legacy_artifact_uploader.rb @@ -1,5 +1,5 @@ -class LegacyArtifactUploader < GitlabUploader - storage :file +class LegacyArtifactUploader < ObjectStoreUploader + storage_options Gitlab.config.artifacts def self.local_store_path Gitlab.config.artifacts.path @@ -9,24 +9,8 @@ class LegacyArtifactUploader < GitlabUploader File.join(self.local_store_path, 'tmp/uploads/') end - def store_dir - default_local_path - end - - def cache_dir - File.join(self.class.local_store_path, 'tmp/cache') - end - - def work_dir - File.join(self.class.local_store_path, 'tmp/work') - end - private - def default_local_path - File.join(self.class.local_store_path, default_path) - end - def default_path File.join(model.created_at.utc.strftime('%Y_%m'), model.project_id.to_s, model.id.to_s) end diff --git a/app/uploaders/lfs_object_uploader.rb b/app/uploaders/lfs_object_uploader.rb index 8a5f599c1d3..88cf0450dcd 100644 --- a/app/uploaders/lfs_object_uploader.rb +++ b/app/uploaders/lfs_object_uploader.rb @@ -7,12 +7,12 @@ class LfsObjectUploader < ObjectStoreUploader end def filename - subject.oid[4..-1] + model.oid[4..-1] end private def default_path - "#{subject.oid[0, 2]}/#{subject.oid[2, 2]}" + "#{model.oid[0, 2]}/#{model.oid[2, 2]}" end end diff --git a/app/uploaders/object_store_uploader.rb b/app/uploaders/object_store_uploader.rb index 9b9f47d5943..b5de0357a5f 100644 --- a/app/uploaders/object_store_uploader.rb +++ b/app/uploaders/object_store_uploader.rb @@ -38,11 +38,16 @@ class ObjectStoreUploader < GitlabUploader end end - attr_reader :subject, :field + def file_storage? + storage.is_a?(CarrierWave::Storage::File) + end + + def file_cache_storage? + cache_storage.is_a?(CarrierWave::Storage::File) + end - def initialize(subject, field) - @subject = subject - @field = field + def real_object_store + model.public_send(store_serialization_column) # rubocop:disable GitlabSecurity/PublicSend end def object_store @@ -51,7 +56,7 @@ class ObjectStoreUploader < GitlabUploader def object_store=(value) @storage = nil - subject.public_send(:"#{field}_store=", value) + model.public_send(:"#{store_serialization_column}=", value) # rubocop:disable GitlabSecurity/PublicSend end def store_dir @@ -99,7 +104,7 @@ class ObjectStoreUploader < GitlabUploader # since we change storage store the new storage # in case of failure delete new file begin - subject.save! + model.save! rescue => e new_file.delete self.object_store = old_store @@ -113,7 +118,7 @@ class ObjectStoreUploader < GitlabUploader def schedule_migration_to_object_storage(new_file) if self.class.object_store_enabled? && licensed? && file_storage? - ObjectStorageUploadWorker.perform_async(self.class.name, subject.class.name, field, subject.id) + ObjectStorageUploadWorker.perform_async(self.class.name, model.class.name, mounted_as, model.id) end end @@ -178,6 +183,14 @@ class ObjectStoreUploader < GitlabUploader raise NotImplementedError end + def serialization_column + model.class.uploader_option(mounted_as, :mount_on) || mounted_as + end + + def store_serialization_column + :"#{serialization_column}_store" + end + def storage @storage ||= if object_store == REMOTE_STORE |