diff options
author | Micaël Bergeron <mbergeron@gitlab.com> | 2018-02-21 19:43:21 +0300 |
---|---|---|
committer | Micaël Bergeron <mbergeron@gitlab.com> | 2018-03-01 18:34:30 +0300 |
commit | 0f1d348d683fdef6c36c3b244c85e59f582ff886 (patch) | |
tree | 5558ab163c6154e76a36b6345d22deb302eacc82 /app/models/upload.rb | |
parent | a2f375e8f74870dcdcfa1c7886bd1c14c80a684e (diff) |
port the object storage to CE
Diffstat (limited to 'app/models/upload.rb')
-rw-r--r-- | app/models/upload.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/app/models/upload.rb b/app/models/upload.rb index 3aca452616c..cf71a7b76fc 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -9,6 +9,8 @@ class Upload < ActiveRecord::Base validates :model, presence: true validates :uploader, presence: true + scope :with_files_stored_locally, -> { where(store: [nil, ObjectStorage::Store::LOCAL]) } + before_save :calculate_checksum!, if: :foreground_checksummable? after_commit :schedule_checksum, if: :checksummable? @@ -34,8 +36,8 @@ class Upload < ActiveRecord::Base self.checksum = Digest::SHA256.file(absolute_path).hexdigest end - def build_uploader - uploader_class.new(model, mount_point, **uploader_context).tap do |uploader| + def build_uploader(mounted_as = nil) + uploader_class.new(model, mounted_as || mount_point).tap do |uploader| uploader.upload = self uploader.retrieve_from_store!(identifier) end @@ -52,6 +54,12 @@ class Upload < ActiveRecord::Base }.compact end + def local? + return true if store.nil? + + store == ObjectStorage::Store::LOCAL + end + private def delete_file! @@ -62,12 +70,6 @@ class Upload < ActiveRecord::Base checksum.nil? && local? && exist? end - def local? - return true if store.nil? - - store == ObjectStorage::Store::LOCAL - end - def foreground_checksummable? checksummable? && size <= CHECKSUM_THRESHOLD end |