Permalink
Browse files

Applied patch from Rob Anderton to fix some binmode and open file iss…

…ues that regressed.
  • Loading branch information...
Jon Yurek
Jon Yurek committed Dec 30, 2008
1 parent 9908421 commit 3cc7ab7d079a5091ab1d4cb09973f358a7856e2c
Showing with 6 additions and 2 deletions.
  1. +3 −0 lib/paperclip/attachment.rb
  2. +1 −1 lib/paperclip/storage.rb
  3. +2 −1 test/iostream_test.rb
@@ -67,6 +67,7 @@ def assign uploaded_file
if uploaded_file.is_a?(Paperclip::Attachment)
uploaded_file = uploaded_file.to_file(:original)
+ close_uploaded_file = uploaded_file.respond_to?(:close)
end
return nil unless valid_assignment?(uploaded_file)
@@ -93,6 +94,7 @@ def assign uploaded_file
# Reset the file size if the original file was reprocessed.
instance_write(:file_size, uploaded_file.size.to_i)
ensure
+ uploaded_file.close if close_uploaded_file
validate
end
@@ -212,6 +214,7 @@ def self.interpolations
# the post-process again.
def reprocess!
new_original = Tempfile.new("paperclip-reprocess")
+ new_original.binmode
if old_original = to_file(:original)
new_original.write( old_original.read )
new_original.rewind
View
@@ -38,11 +38,11 @@ def to_file style = default_style
def flush_writes #:nodoc:
logger.info("[paperclip] Writing files for #{name}")
@queued_for_write.each do |style, file|
+ file.close
FileUtils.mkdir_p(File.dirname(path(style)))
logger.info("[paperclip] -> #{path(style)}")
FileUtils.mv(file.path, path(style))
FileUtils.chmod(0644, path(style))
- file.close
end
@queued_for_write = {}
end
View
@@ -20,7 +20,8 @@ class IOStreamTest < Test::Unit::TestCase
context "and given a String" 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
should "return a File" do

0 comments on commit 3cc7ab7

Please sign in to comment.