diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-03 11:55:40 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-03 11:55:40 +0000 |
commit | 2f83c57be4be14db565961c2b9f0ff85e3e5ff3a (patch) | |
tree | fae61379365ed82e90284b62b70db5bb9d23927e /app/models | |
parent | f0e5437d27f008379b8523ce2b54d697e5e9be94 (diff) | |
download | redmine-2f83c57be4be14db565961c2b9f0ff85e3e5ff3a.tar.gz redmine-2f83c57be4be14db565961c2b9f0ff85e3e5ff3a.zip |
Adds file equality check to deduplication hook (#25215).
Patch by Jens Kraemer.
git-svn-id: http://svn.redmine.org/redmine/trunk@16459 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/attachment.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 8e8cc0ac1..7e6b6bd03 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -422,9 +422,16 @@ class Attachment < ActiveRecord::Base .first original_diskfile = self.diskfile - self.update_columns disk_directory: existing.disk_directory, - disk_filename: existing.disk_filename - File.delete(original_diskfile) if File.exist?(original_diskfile) + existing_diskfile = existing.diskfile + + if File.readable?(original_diskfile) && + File.readable?(existing_diskfile) && + FileUtils.identical?(original_diskfile, existing_diskfile) + + self.update_columns disk_directory: existing.disk_directory, + disk_filename: existing.disk_filename + File.delete(original_diskfile) + end end end end |