From f4aff7919ab1aa6ae3437a2ded73197129892762 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 9 Nov 2013 09:46:55 +0000 Subject: [PATCH] Log errors when moving attachments (#15295). git-svn-id: http://svn.redmine.org/redmine/trunk@12249 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/attachment.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index b289b0f47..d9a02d49e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -265,14 +265,25 @@ class Attachment < ActiveRecord::Base # Moves an existing attachment to its target directory def move_to_target_directory! - if !new_record? & readable? - src = diskfile - self.disk_directory = target_directory - dest = diskfile - if src != dest && FileUtils.mkdir_p(File.dirname(dest)) && FileUtils.mv(src, dest) - update_column :disk_directory, disk_directory - end + return unless !new_record? & readable? + + src = diskfile + self.disk_directory = target_directory + dest = diskfile + + return if src == dest + + if !FileUtils.mkdir_p(File.dirname(dest)) + logger.error "Could not create directory #{File.dirname(dest)}" if logger + return + end + + if !FileUtils.mv(src, dest) + logger.error "Could not move attachment from #{src} to #{dest}" if logger + return end + + update_column :disk_directory, disk_directory end # Moves existing attachments that are stored at the root of the files -- 2.39.5