Commit e321608f by Dan Collis-Puro Committed by Jon Yurek

Revert Paperclip::Storage::Filesystem#flush_writes

This commit makes this method move by default instead of copying, which
should make it perform significantly better with large files. It falls
back to the old semantics if the mv fails.
parent 6a388c73
...@@ -36,11 +36,15 @@ module Paperclip ...@@ -36,11 +36,15 @@ module Paperclip
def flush_writes #:nodoc: def flush_writes #:nodoc:
@queued_for_write.each do |style_name, file| @queued_for_write.each do |style_name, file|
FileUtils.mkdir_p(File.dirname(path(style_name))) FileUtils.mkdir_p(File.dirname(path(style_name)))
begin
FileUtils.mv(file.path, path(style_name))
rescue SystemCallError
File.open(path(style_name), "wb") do |new_file| File.open(path(style_name), "wb") do |new_file|
while chunk = file.read(16 * 1024) while chunk = file.read(16 * 1024)
new_file.write(chunk) new_file.write(chunk)
end end
end end
end
unless @options[:override_file_permissions] == false unless @options[:override_file_permissions] == false
resolved_chmod = (@options[:override_file_permissions] &~ 0111) || (0666 &~ File.umask) resolved_chmod = (@options[:override_file_permissions] &~ 0111) || (0666 &~ File.umask)
FileUtils.chmod( resolved_chmod, path(style_name) ) FileUtils.chmod( resolved_chmod, path(style_name) )
......
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