From cad666f4828841eb4dd0219b72d7a01d21a38056 Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Thu, 9 Mar 2017 22:49:37 -0800 Subject: [PATCH] Remove tempfile if exception is thrown Proactively clean up the tempfile if Av throws an exception and whiny is true. This prevents tempfiles from lingering around unnecessarily until the next GC. See related issue: https://github.com/thoughtbot/paperclip/issues/1326 --- lib/paperclip/paperclip_processors/transcoder.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index d67efea..b28c27c 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -74,9 +74,12 @@ def make begin @cli.run - log "Successfully transcoded #{@basename} to #{dst}" + log "Successfully transcoded #{@basename} to #{dst.path}" rescue Cocaine::ExitStatusError => e - raise Paperclip::Error, "error while transcoding #{@basename}: #{e}" if @whiny + if @whiny + dst.close! + raise Paperclip::Error, "error while transcoding #{@basename}: #{e}" + end end else log "Unsupported file #{@file.path}"