summaryrefslogtreecommitdiff
path: root/app/models/upload.rb
diff options
context:
space:
mode:
authorMicaël Bergeron <mbergeron@gitlab.com>2018-01-30 09:21:28 -0500
committerMicaël Bergeron <mbergeron@gitlab.com>2018-02-06 08:48:35 -0500
commitd84650917ae3eee95fc0aae31ad49fe824fe71d2 (patch)
tree7ed734af7ca6ae616e3ee159fe7e72238c23ec46 /app/models/upload.rb
parentb9d547b12c3731160c456f3f20366e600ab99484 (diff)
downloadgitlab-ce-d84650917ae3eee95fc0aae31ad49fe824fe71d2.tar.gz
remove file after `Upload#destroy`
it will also automatically prune empty directories for `FileUploader`-based uploaders.
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..1bbcc4e381d 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_commit :delete_file!, on: :destroy, 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