Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-02-28 23:14:25 +0300
committerKamil Trzciński <ayufan@ayufan.eu>2018-02-28 23:14:25 +0300
commit79a5e7fb539dc6df7de590efb69fb9ab9d4614eb (patch)
tree951e2f3194c4b4d5488864791a9a94afe7122280 /app/models/upload.rb
parent729391fbfce4dea58478b65c684a24a1bfd125a2 (diff)
parent7e424eb852716495073881710e8a8851b4a4cd5a (diff)
Merge commit '7e424eb852716495073881710e8a8851b4a4cd5a' into object-storage-ee-to-ce-backport
Diffstat (limited to 'app/models/upload.rb')
-rw-r--r--app/models/upload.rb25
1 files changed, 22 insertions, 3 deletions
diff --git a/app/models/upload.rb b/app/models/upload.rb
index e227baea994..3aca452616c 100644
--- a/app/models/upload.rb
+++ b/app/models/upload.rb
@@ -12,6 +12,10 @@ class Upload < ActiveRecord::Base
before_save :calculate_checksum!, if: :foreground_checksummable?
after_commit :schedule_checksum, if: :checksummable?
+ # as the FileUploader is not mounted, the default CarrierWave ActiveRecord
+ # hooks are not executed and the file will not be deleted
+ after_destroy :delete_file!, if: -> { uploader_class <= FileUploader }
+
def self.hexdigest(path)
Digest::SHA256.file(path).hexdigest
end
@@ -31,7 +35,7 @@ class Upload < ActiveRecord::Base
end
def build_uploader
- uploader_class.new(model).tap do |uploader|
+ uploader_class.new(model, mount_point, **uploader_context).tap do |uploader|
uploader.upload = self
uploader.retrieve_from_store!(identifier)
end
@@ -41,8 +45,19 @@ class Upload < ActiveRecord::Base
File.exist?(absolute_path)
end
+ def uploader_context
+ {
+ identifier: identifier,
+ secret: secret
+ }.compact
+ end
+
private
+ def delete_file!
+ build_uploader.remove!
+ end
+
def checksummable?
checksum.nil? && local? && exist?
end
@@ -65,11 +80,15 @@ class Upload < ActiveRecord::Base
!path.start_with?('/')
end
+ def uploader_class
+ Object.const_get(uploader)
+ end
+
def identifier
File.basename(path)
end
- def uploader_class
- Object.const_get(uploader)
+ def mount_point
+ super&.to_sym
end
end