diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-06-20 12:06:00 +0200 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-06-20 12:06:00 +0200 |
commit | bf8ad0b5271274bc6bc06a27d1e8f109b660961a (patch) | |
tree | 4cb20e637cbe6c0cc2b96d44d62871b0af969da0 | |
parent | e0da61bca80485b99f78ef1dbb3c64578d64d55a (diff) | |
download | gitlab-ce-bf8ad0b5271274bc6bc06a27d1e8f109b660961a.tar.gz |
Test: Delete uploads after commitjprovazn-uploads2
-rw-r--r-- | app/models/concerns/with_uploads.rb | 5 | ||||
-rw-r--r-- | app/models/upload.rb | 14 |
2 files changed, 10 insertions, 9 deletions
diff --git a/app/models/concerns/with_uploads.rb b/app/models/concerns/with_uploads.rb index 4245d083a49..bd203562cbd 100644 --- a/app/models/concerns/with_uploads.rb +++ b/app/models/concerns/with_uploads.rb @@ -24,7 +24,7 @@ module WithUploads included do has_many :uploads, as: :model - before_destroy :destroy_file_uploads + after_commit :destroy_file_uploads, on: :destroy end # mounted uploads are deleted in carrierwave's after_commit hook, @@ -33,7 +33,8 @@ module WithUploads # associated model on destroy (which is already deleted in after_commit) def destroy_file_uploads self.uploads.where(uploader: FILE_UPLOADERS).find_each do |upload| - upload.destroy + upload.delete_file!(self) + upload.delete end end diff --git a/app/models/upload.rb b/app/models/upload.rb index cf71a7b76fc..62f8eaa686f 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -16,7 +16,7 @@ class Upload < ActiveRecord::Base # 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 } + #after_destroy :delete_file!, if: -> { uploader_class <= FileUploader } def self.hexdigest(path) Digest::SHA256.file(path).hexdigest @@ -36,8 +36,8 @@ class Upload < ActiveRecord::Base self.checksum = Digest::SHA256.file(absolute_path).hexdigest end - def build_uploader(mounted_as = nil) - uploader_class.new(model, mounted_as || mount_point).tap do |uploader| + def build_uploader(mounted_as = nil, parent = nil) + uploader_class.new(parent || model, mounted_as || mount_point).tap do |uploader| uploader.upload = self uploader.retrieve_from_store!(identifier) end @@ -60,12 +60,12 @@ class Upload < ActiveRecord::Base store == ObjectStorage::Store::LOCAL end - private - - def delete_file! - build_uploader.remove! + def delete_file!(parent = nil) + build_uploader(nil, parent).remove! end + private + def checksummable? checksum.nil? && local? && exist? end |