Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Temp directory overflow issue #1321

Merged
merged 3 commits into from

2 participants

@dimko

Synopsis

Every MiniMagick::Image.open(path) call creates a temp file, which is not deleted after manipulating.
This leads to overflow of tmp directory under high load.

Pull Request

  1. Validate out image with identify command instead of opening an image.
  2. Delete temp file after manipulating.
@bensie bensie merged commit 28a4363 into carrierwaveuploader:master
@bensie
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 5 deletions.
  1. +12 −5 lib/carrierwave/processing/mini_magick.rb
View
17 lib/carrierwave/processing/mini_magick.rb
@@ -258,12 +258,19 @@ def resize_and_pad(width, height, background=:transparent, gravity='Center')
def manipulate!
cache_stored_file! if !cached?
image = ::MiniMagick::Image.open(current_path)
- image.format(@format.to_s.downcase) if @format
- image = yield(image)
- image.write(current_path)
- ::MiniMagick::Image.open(current_path)
+
+ begin
+ image.format(@format.to_s.downcase) if @format
+ image = yield(image)
+ image.write(current_path)
+ image.run_command("identify", current_path)
+ ensure
+ image.destroy!
+ end
rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
- raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :default => I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :locale => :en))
+ default = I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :locale => :en)
+ message = I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :default => default)
+ raise CarrierWave::ProcessingError, message
end
end # MiniMagick
Something went wrong with that request. Please try again.