Commit 87cebf99 by lister Committed by Jon Yurek

Update attachment.rb

Add explicit unlink to intermediate files from processors.
parent 6a5b30cf
......@@ -515,9 +515,14 @@ module Paperclip
def post_process_style(name, style) #:nodoc:
begin
raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
intermediate_files = []
@queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
Paperclip.processor(processor).make(file, style.processor_options, self)
file = Paperclip.processor(processor).make(file, style.processor_options, self)
intermediate_files << file
file
end
unadapted_file = @queued_for_write[name]
@queued_for_write[name] = Paperclip.io_adapters.for(@queued_for_write[name])
unadapted_file.close if unadapted_file.respond_to?(:close)
......@@ -525,6 +530,8 @@ module Paperclip
rescue Paperclip::Error => e
log("An error was received while processing: #{e.inspect}")
(@errors[:processing] ||= []) << e.message if @options[:whiny]
ensure
unlink_files(intermediate_files)
end
end
......@@ -565,7 +572,11 @@ module Paperclip
# called by storage after the writes are flushed and before @queued_for_write is cleared
def after_flush_writes
@queued_for_write.each do |style, file|
unlink_files(@queued_for_write.values)
end
def unlink_files(files)
Array(files).each do |file|
file.close unless file.closed?
file.unlink if file.respond_to?(:unlink) && file.path.present? && File.exist?(file.path)
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