0001-fix-creation-of-multiple-identical-attachments-in-ou.patch

Jens Krämer, 2020-07-26 10:19

Download (1.96 KB)

View differences:

app/models/attachment.rb
470 470
                      .where(digest: self.digest, filesize: self.filesize)
471 471
                      .where('id <> ? and disk_filename <> ?',
472 472
                             self.id, self.disk_filename)
473
                      .first
473
                      .order(:id)
474
                      .last
474 475
        existing.with_lock do
475 476
          original_diskfile = self.diskfile
476 477
          existing_diskfile = existing.diskfile
test/unit/attachment_test.rb
235 235
    assert_not_equal a1.diskfile, a2.diskfile
236 236
  end
237 237

  
238
  def test_identical_attachments_created_in_same_transaction_should_not_end_up_unreadable
239
    attachments = []
240
    Project.transaction do
241
      3.times do
242
        a = Attachment.create!(
243
          :container => Issue.find(1), :author => User.find(1),
244
          :file => mock_file(:filename => 'foo', :content => 'abcde')
245
        )
246
        attachments << a
247
      end
248
    end
249
    attachments.each do |a|
250
      assert a.readable?
251
    end
252
    assert_equal 1, attachments.map(&:diskfile).uniq.size
253
  end
254

  
238 255
  def test_filename_should_be_basenamed
239 256
    a = Attachment.new(:file => mock_file(:original_filename => "path/to/the/file"))
240 257
    assert_equal 'file', a.filename
241
-