From 0e407dcf46f0436393db16b67ed6d73922302f61 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 3 Apr 2017 12:13:07 +0000 Subject: [PATCH] Delete the file after the change is committed (#25215). git-svn-id: http://svn.redmine.org/redmine/trunk@16460 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/attachment.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 7e6b6bd03..26fe4a8b3 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -413,7 +413,9 @@ class Attachment < ActiveRecord::Base private def reuse_existing_file_if_possible - with_lock do + original_diskfile = nil + + reused = with_lock do if existing = Attachment .lock .where(digest: self.digest, filesize: self.filesize) @@ -430,10 +432,12 @@ class Attachment < ActiveRecord::Base self.update_columns disk_directory: existing.disk_directory, disk_filename: existing.disk_filename - File.delete(original_diskfile) end end end + if reused + File.delete(original_diskfile) + end end