Commit 281a7553 by Mike Burns

Merge branch 'features/tempfile_cleanup' of https://github.com/danielevans/paperclip

parents 630c6341 89ecde48
...@@ -420,5 +420,13 @@ module Paperclip ...@@ -420,5 +420,13 @@ module Paperclip
end end
end end
# called by storage after the writes are flushed and before @queued_for_writes is cleared
def after_flush_writes
@queued_for_write.each do |style, file|
file.close unless file.closed?
file.unlink if file.respond_to?(:unlink) && file.path.present? && File.exist?(file.path)
end
end
end end
end end
...@@ -46,6 +46,9 @@ module Paperclip ...@@ -46,6 +46,9 @@ module Paperclip
end end
FileUtils.chmod(0666&~File.umask, path(style_name)) FileUtils.chmod(0666&~File.umask, path(style_name))
end end
after_flush_writes # allows attachment to clean up temp files
@queued_for_write = {} @queued_for_write = {}
end end
......
...@@ -82,6 +82,9 @@ module Paperclip ...@@ -82,6 +82,9 @@ module Paperclip
retry retry
end end
end end
after_flush_writes # allows attachment to clean up temp files
@queued_for_write = {} @queued_for_write = {}
end end
......
...@@ -196,6 +196,9 @@ module Paperclip ...@@ -196,6 +196,9 @@ module Paperclip
raise raise
end end
end end
after_flush_writes # allows attachment to clean up temp files
@queued_for_write = {} @queued_for_write = {}
end end
......
...@@ -57,6 +57,14 @@ class FogTest < Test::Unit::TestCase ...@@ -57,6 +57,14 @@ class FogTest < Test::Unit::TestCase
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../public/avatars/5k.png")), assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../public/avatars/5k.png")),
@dummy.avatar.path @dummy.avatar.path
end end
should "clean up file objects" do
File.stubs(:exist?).returns(true)
Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
@dummy.save!
end
end end
setup do setup do
......
...@@ -29,6 +29,14 @@ class StorageTest < Test::Unit::TestCase ...@@ -29,6 +29,14 @@ class StorageTest < Test::Unit::TestCase
@dummy.save @dummy.save
assert File.exists?(@dummy.avatar.path(:thumbnail)) assert File.exists?(@dummy.avatar.path(:thumbnail))
end end
should "clean up file objects" do
File.stubs(:exist?).returns(true)
Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
@dummy.save!
end
end end
context "Parsing S3 credentials" do context "Parsing S3 credentials" do
...@@ -349,6 +357,15 @@ class StorageTest < Test::Unit::TestCase ...@@ -349,6 +357,15 @@ class StorageTest < Test::Unit::TestCase
end end
end end
should "delete tempfiles" do
AWS::S3::S3Object.stubs(:store).with(@dummy.avatar.path, anything, 'testing', :content_type => 'image/png', :access => :public_read)
File.stubs(:exist?).returns(true)
Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
@dummy.save!
end
context "and saved without a bucket" do context "and saved without a bucket" do
setup do setup do
class AWS::S3::NoSuchBucket < AWS::S3::ResponseError class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
......
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