]> source.dussan.org Git - redmine.git/commitdiff
Log errors when moving attachments (#15295).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 9 Nov 2013 09:46:55 +0000 (09:46 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 9 Nov 2013 09:46:55 +0000 (09:46 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12249 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb

index b289b0f479ce0dc416d7a6b05f3d3daa1fd032ea..d9a02d49eb0dcd1df545ebfa0589028b31fdafbd 100644 (file)
@@ -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