Patch #34479 » 0001-introduces-an-additional-check-before-removing-a-ded.patch
app/models/attachment.rb | ||
---|---|---|
479 | 479 |
private |
480 | 480 | |
481 | 481 |
def reuse_existing_file_if_possible |
482 |
original_diskfile = nil |
|
482 |
original_diskfile = diskfile |
|
483 |
original_filename = disk_filename |
|
483 | 484 |
reused = with_lock do |
484 | 485 |
if existing = Attachment |
485 | 486 |
.where(digest: self.digest, filesize: self.filesize) |
486 |
.where('id <> ? and disk_filename <> ?', |
|
487 |
self.id, self.disk_filename) |
|
487 |
.where.not(disk_filename: original_filename) |
|
488 | 488 |
.order(:id) |
489 | 489 |
.last |
490 | 490 |
existing.with_lock do |
491 |
original_diskfile = self.diskfile |
|
492 | 491 |
existing_diskfile = existing.diskfile |
493 | 492 |
if File.readable?(original_diskfile) && |
494 | 493 |
File.readable?(existing_diskfile) && |
... | ... | |
499 | 498 |
end |
500 | 499 |
end |
501 | 500 |
end |
502 |
if reused |
|
501 |
if reused && Attachment.where(disk_filename: original_filename).none?
|
|
503 | 502 |
File.delete(original_diskfile) |
504 | 503 |
end |
505 | 504 |
rescue ActiveRecord::StatementInvalid, ActiveRecord::RecordNotFound |