RM_15295_attachement_file_move_to_subdir_error_messages_RM_V2.3.2.diff

Jérôme BATAILLE, 2013-11-07 16:05

Download (1.12 KB)

View differences:

app/models/attachment.rb (copie de travail)
265 265

  
266 266
  # Moves an existing attachment to its target directory
267 267
  def move_to_target_directory!
268
    if !new_record? & readable?
269
      src = diskfile
270
      self.disk_directory = target_directory
271
      dest = diskfile
272
      if src != dest && FileUtils.mkdir_p(File.dirname(dest)) && FileUtils.mv(src, dest)
273
        update_column :disk_directory, disk_directory
274
      end
268
    return unless !new_record? & readable?
269

  
270
    src = diskfile
271
    self.disk_directory = target_directory
272
    dest = diskfile
273

  
274
    return if src == dest
275

  
276
    if !FileUtils.mkdir_p(File.dirname(dest))
277
      echo "Could not mkdir #{File.dirname(dest)} !"
278
      return
275 279
    end
280

  
281
    if !FileUtils.mv(src, dest)
282
      echo "Could not mv #{src} -> #{dest} !"
283
      return
284
    end
285

  
286
    puts "#{src} -> #{dest}"
287
    update_column :disk_directory, disk_directory
276 288
  end
277 289

  
278 290
  # Moves existing attachments that are stored at the root of the files