diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-11-09 09:46:55 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-11-09 09:46:55 +0000 |
commit | f4aff7919ab1aa6ae3437a2ded73197129892762 (patch) | |
tree | 2da550c3b4c087e7e458e29a4b08d6d6f3c970b0 /app/models/attachment.rb | |
parent | 10e29f22239e899072d922e2788843ee3785a76d (diff) | |
download | redmine-f4aff7919ab1aa6ae3437a2ded73197129892762.tar.gz redmine-f4aff7919ab1aa6ae3437a2ded73197129892762.zip |
Log errors when moving attachments (#15295).
git-svn-id: http://svn.redmine.org/redmine/trunk@12249 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/attachment.rb')
-rw-r--r-- | app/models/attachment.rb | 25 |
1 files 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 |