diff --git a/lib/image_optim.rb b/lib/image_optim.rb index 2bf23c67..de5ca2d1 100644 --- a/lib/image_optim.rb +++ b/lib/image_optim.rb @@ -75,6 +75,7 @@ def optimize_image(original) worker.optimize(src, dst) end end + handler.cleanup if handler.result ImagePath::Optimized.new(handler.result, original) end diff --git a/lib/image_optim/handler.rb b/lib/image_optim/handler.rb index 13e5c4bf..360b1dee 100644 --- a/lib/image_optim/handler.rb +++ b/lib/image_optim/handler.rb @@ -23,5 +23,13 @@ def process end end end + + # Remove extra temp files + def cleanup + if @dst + @dst.unlink + @dst = nil + end + end end end diff --git a/spec/image_optim/handler_spec.rb b/spec/image_optim/handler_spec.rb index db9bbb3b..ef35eb5b 100644 --- a/spec/image_optim/handler_spec.rb +++ b/spec/image_optim/handler_spec.rb @@ -40,5 +40,9 @@ [src, dst].should == [temp_a, temp_b]; true end handler.result.should == temp_b + + temp_a.should_receive(:unlink).once + handler.cleanup + handler.cleanup end end