Commit 3cc7ab7d by Jon Yurek

Applied patch from Rob Anderton to fix some binmode and open file issues that regressed.

parent 9908421d
...@@ -67,6 +67,7 @@ module Paperclip ...@@ -67,6 +67,7 @@ module Paperclip
if uploaded_file.is_a?(Paperclip::Attachment) if uploaded_file.is_a?(Paperclip::Attachment)
uploaded_file = uploaded_file.to_file(:original) uploaded_file = uploaded_file.to_file(:original)
close_uploaded_file = uploaded_file.respond_to?(:close)
end end
return nil unless valid_assignment?(uploaded_file) return nil unless valid_assignment?(uploaded_file)
...@@ -93,6 +94,7 @@ module Paperclip ...@@ -93,6 +94,7 @@ module Paperclip
# Reset the file size if the original file was reprocessed. # Reset the file size if the original file was reprocessed.
instance_write(:file_size, uploaded_file.size.to_i) instance_write(:file_size, uploaded_file.size.to_i)
ensure ensure
uploaded_file.close if close_uploaded_file
validate validate
end end
...@@ -212,6 +214,7 @@ module Paperclip ...@@ -212,6 +214,7 @@ module Paperclip
# the post-process again. # the post-process again.
def reprocess! def reprocess!
new_original = Tempfile.new("paperclip-reprocess") new_original = Tempfile.new("paperclip-reprocess")
new_original.binmode
if old_original = to_file(:original) if old_original = to_file(:original)
new_original.write( old_original.read ) new_original.write( old_original.read )
new_original.rewind new_original.rewind
......
...@@ -38,11 +38,11 @@ module Paperclip ...@@ -38,11 +38,11 @@ module Paperclip
def flush_writes #:nodoc: def flush_writes #:nodoc:
logger.info("[paperclip] Writing files for #{name}") logger.info("[paperclip] Writing files for #{name}")
@queued_for_write.each do |style, file| @queued_for_write.each do |style, file|
file.close
FileUtils.mkdir_p(File.dirname(path(style))) FileUtils.mkdir_p(File.dirname(path(style)))
logger.info("[paperclip] -> #{path(style)}") logger.info("[paperclip] -> #{path(style)}")
FileUtils.mv(file.path, path(style)) FileUtils.mv(file.path, path(style))
FileUtils.chmod(0644, path(style)) FileUtils.chmod(0644, path(style))
file.close
end end
@queued_for_write = {} @queued_for_write = {}
end end
......
...@@ -20,7 +20,8 @@ class IOStreamTest < Test::Unit::TestCase ...@@ -20,7 +20,8 @@ class IOStreamTest < Test::Unit::TestCase
context "and given a String" do context "and given a String" do
setup do setup do
assert @result = @file.stream_to("/tmp/iostream.string.test") FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
assert @result = @file.stream_to(File.join(ROOT, 'tmp', 'iostream.string.test'))
end end
should "return a File" do should "return a File" do
......
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