diff options
author | Go MAEDA <maeda@farend.jp> | 2021-03-17 13:46:18 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-03-17 13:46:18 +0000 |
commit | a8170e6a14f42b3361ea046918f921615a9408c6 (patch) | |
tree | fac2bd41911a8d23fe50fec2a47004b709fa37dd /app/models/attachment.rb | |
parent | 7c824702c282ac3ecc31f6eee18f459da218218a (diff) | |
download | redmine-a8170e6a14f42b3361ea046918f921615a9408c6.tar.gz redmine-a8170e6a14f42b3361ea046918f921615a9408c6.zip |
Introduces an additional check before removing a deduplicated file (#34479).
Patch by Jens Krämer.
git-svn-id: http://svn.redmine.org/redmine/trunk@20812 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/attachment.rb')
-rw-r--r-- | app/models/attachment.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 7bce5ded6..3ffb1b51d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -496,16 +496,15 @@ class Attachment < ActiveRecord::Base private def reuse_existing_file_if_possible - original_diskfile = nil + original_diskfile = diskfile + original_filename = disk_filename reused = with_lock do if existing = Attachment .where(digest: self.digest, filesize: self.filesize) - .where('id <> ? and disk_filename <> ?', - self.id, self.disk_filename) + .where.not(disk_filename: original_filename) .order(:id) .last existing.with_lock do - original_diskfile = self.diskfile existing_diskfile = existing.diskfile if File.readable?(original_diskfile) && File.readable?(existing_diskfile) && @@ -516,7 +515,7 @@ class Attachment < ActiveRecord::Base end end end - if reused + if reused && Attachment.where(disk_filename: original_filename).none? File.delete(original_diskfile) end rescue ActiveRecord::StatementInvalid, ActiveRecord::RecordNotFound |