Commit 33ba2fd2 by Akihiko Odaki Committed by Sid Raval

Reopen file even when copying instead of linking (#2545)

parent 2c0760b5
......@@ -57,15 +57,16 @@ module Paperclip
end
def link_or_copy_file(src, dest)
Paperclip.log("Trying to link #{src} to #{dest}")
FileUtils.ln(src, dest, force: true) # overwrite existing
@destination.close
@destination.open.binmode
rescue Errno::EXDEV, Errno::EPERM, Errno::ENOENT, Errno::EEXIST => e
Paperclip.log(
"Link failed with #{e.message}; copying link #{src} to #{dest}"
)
FileUtils.cp(src, dest)
begin
Paperclip.log("Trying to link #{src} to #{dest}")
FileUtils.ln(src, dest, force: true) # overwrite existing
rescue Errno::EXDEV, Errno::EPERM, Errno::ENOENT, Errno::EEXIST => e
Paperclip.log(
"Link failed with #{e.message}; copying link #{src} to #{dest}"
)
FileUtils.cp(src, dest)
end
@destination.close
@destination.open.binmode
end
......
......@@ -93,6 +93,34 @@ describe Paperclip::AbstractAdapter do
end
end
context "#copy_to_tempfile" do
around do |example|
FileUtils.module_eval do
class << self
alias paperclip_ln ln
def ln(*)
raise Errno::EXDEV
end
end
end
example.run
FileUtils.module_eval do
class << self
alias ln paperclip_ln
undef paperclip_ln
end
end
end
it "should return a readable file even when linking fails" do
src = open(fixture_file("5k.png"), "rb")
expect(subject.send(:copy_to_tempfile, src).read).to eq src.read
end
end
context "#original_filename=" do
it "should not fail with a nil original filename" do
expect { subject.original_filename = nil }.not_to raise_error
......
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