Patch #30177 » 0002-deletes-thumbnails-when-the-attachment-diskfile-is-d.patch
app/models/attachment.rb | ||
---|---|---|
216 | 216 |
size = Setting.thumbnails_size.to_i |
217 | 217 |
end |
218 | 218 |
size = 100 unless size > 0 |
219 |
target = File.join(self.class.thumbnails_storage_path, "#{digest}_#{filesize}_#{size}.thumb")
|
|
219 |
target = thumbnail_path(size)
|
|
220 | 220 | |
221 | 221 |
begin |
222 | 222 |
Redmine::Thumbnail.generate(self.diskfile, target, size) |
... | ... | |
463 | 463 |
if disk_filename.present? && File.exist?(diskfile) |
464 | 464 |
File.delete(diskfile) |
465 | 465 |
end |
466 |
Dir[thumbnail_path("*")].each do |thumb| |
|
467 |
File.delete(thumb) |
|
468 |
end |
|
469 |
end |
|
470 | ||
471 |
def thumbnail_path(size) |
|
472 |
File.join(self.class.thumbnails_storage_path, |
|
473 |
"#{digest}_#{filesize}_#{size}.thumb") |
|
466 | 474 |
end |
467 | 475 | |
468 | 476 |
def sanitize_filename(value) |
test/unit/attachment_test.rb | ||
---|---|---|
456 | 456 |
assert_equal a_thumb, b_thumb |
457 | 457 |
end |
458 | 458 | |
459 |
def test_destroy_should_destroy_thumbnails |
|
460 |
a = Attachment.create!( |
|
461 |
:container => Issue.find(1), |
|
462 |
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"), |
|
463 |
:author => User.find(1) |
|
464 |
) |
|
465 |
diskfile = a.diskfile |
|
466 |
thumbnail = a.thumbnail |
|
467 |
assert File.exist?(diskfile) |
|
468 |
assert File.exist?(thumbnail) |
|
469 |
assert a.destroy |
|
470 |
refute File.exist?(diskfile) |
|
471 |
refute File.exist?(thumbnail) |
|
472 |
end |
|
473 | ||
459 | 474 |
def test_thumbnail_should_return_nil_if_generation_fails |
460 | 475 |
Redmine::Thumbnail.expects(:generate).raises(SystemCallError, 'Something went wrong') |
461 | 476 |
set_fixtures_attachments_directory |
- « Previous
- 1
- 2
- Next »