Commit 0bd30e22 by Michael Raidel Committed by Sid Raval

fix fallback when symlink in AbstractAdapter#link_or_copy_file fails

parent 2f4015de
...@@ -62,7 +62,9 @@ module Paperclip ...@@ -62,7 +62,9 @@ module Paperclip
@destination.close @destination.close
@destination.open.binmode @destination.open.binmode
rescue Errno::EXDEV, Errno::EPERM, Errno::ENOENT, Errno::EEXIST => e rescue Errno::EXDEV, Errno::EPERM, Errno::ENOENT, Errno::EEXIST => e
Paperclip.log("Link failed with #{e.message}; copying link #{src} to #{dest}") Paperclip.log(
"Link failed with #{e.message}; copying link #{src} to #{dest}"
)
FileUtils.cp(src, dest) FileUtils.cp(src, dest)
@destination.close @destination.close
@destination.open.binmode @destination.open.binmode
......
...@@ -98,4 +98,39 @@ describe Paperclip::AbstractAdapter do ...@@ -98,4 +98,39 @@ describe Paperclip::AbstractAdapter do
expect { subject.original_filename = nil }.not_to raise_error expect { subject.original_filename = nil }.not_to raise_error
end end
end end
context "#link_or_copy_file" do
class TestLinkOrCopyAdapter < Paperclip::AbstractAdapter
public :copy_to_tempfile, :destination
end
subject { TestLinkOrCopyAdapter.new(nil) }
let(:body) { "body" }
let(:file) do
t = Tempfile.new("destination")
t.print(body)
t.rewind
t
end
after do
file.close
file.unlink
end
it "should be able to read the file" do
expect(subject.copy_to_tempfile(file).read).to eq(body)
end
it "should be able to reopen the file after symlink has failed" do
FileUtils.expects(:ln).raises(Errno::EXDEV)
# after the failed symlink the file reports a size of zero
# which makes it necessary to reopen it
# we simulate this condition by closing the file
subject.destination.close
expect(subject.copy_to_tempfile(file).read).to eq(body)
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