@@ -265,14 +265,25 class Attachment < ActiveRecord::Base | |||||
265 |
|
265 | |||
266 | # Moves an existing attachment to its target directory |
|
266 | # Moves an existing attachment to its target directory | |
267 | def move_to_target_directory! |
|
267 | def move_to_target_directory! | |
268 |
|
|
268 | return unless !new_record? & readable? | |
269 | src = diskfile |
|
269 | ||
270 | self.disk_directory = target_directory |
|
270 | src = diskfile | |
271 | dest = diskfile |
|
271 | self.disk_directory = target_directory | |
272 | if src != dest && FileUtils.mkdir_p(File.dirname(dest)) && FileUtils.mv(src, dest) |
|
272 | dest = diskfile | |
273 | update_column :disk_directory, disk_directory |
|
273 | ||
274 | end |
|
274 | return if src == dest | |
|
275 | ||||
|
276 | if !FileUtils.mkdir_p(File.dirname(dest)) | |||
|
277 | logger.error "Could not create directory #{File.dirname(dest)}" if logger | |||
|
278 | return | |||
|
279 | end | |||
|
280 | ||||
|
281 | if !FileUtils.mv(src, dest) | |||
|
282 | logger.error "Could not move attachment from #{src} to #{dest}" if logger | |||
|
283 | return | |||
275 | end |
|
284 | end | |
|
285 | ||||
|
286 | update_column :disk_directory, disk_directory | |||
276 | end |
|
287 | end | |
277 |
|
288 | |||
278 | # Moves existing attachments that are stored at the root of the files |
|
289 | # Moves existing attachments that are stored at the root of the files |
General Comments 0
You need to be logged in to leave comments.
Login now