diff options
| author | Sean McGivern <sean@gitlab.com> | 2018-03-30 12:58:20 +0100 |
|---|---|---|
| committer | Sean McGivern <sean@gitlab.com> | 2018-03-30 12:58:20 +0100 |
| commit | 6412c4c54a7a824e108899a34b1ecec5cbdcec4b (patch) | |
| tree | afe9fa7485520c60d91315d8f73c6f1d64108c8c /app/models/upload.rb | |
| parent | ddb23d3b2ba7c646cff6a5d21957194fc3474418 (diff) | |
| parent | fa1eabe8e82f7635f2aa51733c727728577c7644 (diff) | |
| download | gitlab-ce-6412c4c54a7a824e108899a34b1ecec5cbdcec4b.tar.gz | |
Merge branch 'master' into stuartnelson3/gitlab-ce-stn/issue-due-email
Diffstat (limited to 'app/models/upload.rb')
| -rw-r--r-- | app/models/upload.rb | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/app/models/upload.rb b/app/models/upload.rb index 99ad37dc892..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? @@ -21,6 +23,7 @@ class Upload < ActiveRecord::Base end def absolute_path + raise ObjectStorage::RemoteStoreError, "Remote object has no absolute path." unless local? return path unless relative_path? uploader_class.absolute_path(self) @@ -30,11 +33,11 @@ class Upload < ActiveRecord::Base self.checksum = nil return unless checksummable? - self.checksum = self.class.hexdigest(absolute_path) + 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 @@ -51,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! @@ -61,10 +70,6 @@ class Upload < ActiveRecord::Base checksum.nil? && local? && exist? end - def local? - true - end - def foreground_checksummable? checksummable? && size <= CHECKSUM_THRESHOLD end |
