Commit 76622ab9 authored by maeda's avatar maeda

Deletes thumbnails when the attachment diskfile is deleted (#30177).

Patch by Jens Krämer.


git-svn-id: https://svn.redmine.org/redmine/trunk@17736 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 2ed8f6b6
......@@ -216,7 +216,7 @@ class Attachment < ActiveRecord::Base
size = Setting.thumbnails_size.to_i
end
size = 100 unless size > 0
target = File.join(self.class.thumbnails_storage_path, "#{digest}_#{filesize}_#{size}.thumb")
target = thumbnail_path(size)
begin
Redmine::Thumbnail.generate(self.diskfile, target, size)
......@@ -463,6 +463,14 @@ class Attachment < ActiveRecord::Base
if disk_filename.present? && File.exist?(diskfile)
File.delete(diskfile)
end
Dir[thumbnail_path("*")].each do |thumb|
File.delete(thumb)
end
end
def thumbnail_path(size)
File.join(self.class.thumbnails_storage_path,
"#{digest}_#{filesize}_#{size}.thumb")
end
def sanitize_filename(value)
......
......@@ -457,6 +457,21 @@ class AttachmentTest < ActiveSupport::TestCase
assert_equal a_thumb, b_thumb
end
def test_destroy_should_destroy_thumbnails
a = Attachment.create!(
:container => Issue.find(1),
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"),
:author => User.find(1)
)
diskfile = a.diskfile
thumbnail = a.thumbnail
assert File.exist?(diskfile)
assert File.exist?(thumbnail)
assert a.destroy
refute File.exist?(diskfile)
refute File.exist?(thumbnail)
end
def test_thumbnail_should_return_nil_if_generation_fails
Redmine::Thumbnail.expects(:generate).raises(SystemCallError, 'Something went wrong')
set_fixtures_attachments_directory
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment