Commit c81970d9 by Sammy Larbi

Fix for Errno::ENAMETOOLONG in Thumbnails

* Uses Paperclip's Tempfile instead of Ruby's in Thumbnail
* Also includes a test for TempfileFactory to be sure it does not revert to similar behavior
* In the tests, give the OS some wiggle room in the Tempfile name to ensure the error does not occur before we are ready for it. The wiggle room is needed because the randomized part of the name has a variable number of characters.
parent cdbc05eb
...@@ -63,8 +63,8 @@ module Paperclip ...@@ -63,8 +63,8 @@ module Paperclip
# that contains the new image. # that contains the new image.
def make def make
src = @file src = @file
dst = Tempfile.new([@basename, @format ? ".#{@format}" : '']) filename = [@basename, @format ? ".#{@format}" : ""].join
dst.binmode dst = TempfileFactory.new.generate(filename)
begin begin
parameters = [] parameters = []
......
...@@ -26,4 +26,8 @@ describe Paperclip::TempfileFactory do ...@@ -26,4 +26,8 @@ describe Paperclip::TempfileFactory do
file = subject.generate file = subject.generate
assert File.exist?(file.path) assert File.exist?(file.path)
end end
it "does not throw Errno::ENAMETOOLONG when it has a really long name" do
expect { subject.generate("o" * 255) }.to_not raise_error
end
end end
...@@ -481,4 +481,20 @@ describe Paperclip::Thumbnail do ...@@ -481,4 +481,20 @@ describe Paperclip::Thumbnail do
end end
end end
end end
context "with a really long file name" do
before do
tempfile = Tempfile.new("f")
tempfile_additional_chars = tempfile.path.split("/")[-1].length + 15
image_file = File.new(fixture_file("5k.png"), "rb")
@file = Tempfile.new("f" * (255 - tempfile_additional_chars))
@file.write(image_file.read)
@file.rewind
end
it "does not throw Errno::ENAMETOOLONG" do
thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
expect { thumb.make }.to_not raise_error
end
end
end end
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