summaryrefslogtreecommitdiff
path: root/app/models/upload.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/upload.rb')
-rw-r--r--app/models/upload.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/upload.rb b/app/models/upload.rb
index 2024228537a..99ad37dc892 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
@@ -49,6 +53,10 @@ class Upload < ActiveRecord::Base
private
+ def delete_file!
+ build_uploader.remove!
+ end
+
def checksummable?
checksum.nil? && local? && exist?
end