From: Raphaƫl Pinson Date: Fri, 18 Jan 2013 20:29:29 +0000 (+0100) Subject: validate_cmd: Make sure tmpfile is always closed and unlinked X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=bda25ac0872a101b59d8ab473218ff0f14bb7433;p=puppet-stdlib.git validate_cmd: Make sure tmpfile is always closed and unlinked --- diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index e7793c3..00fe1ae 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -28,11 +28,14 @@ module Puppet::Parser::Functions # Test content in a temporary file tmpfile = Tempfile.new("validate_cmd") - tmpfile.write(content) - tmpfile.close - output = `#{checkscript} #{tmpfile.path} 2>&1 1>/dev/null` - r = $? - File.delete(tmpfile.path) + begin + tmpfile.write(content) + output = `#{checkscript} #{tmpfile.path} 2>&1 1>/dev/null` + r = $? + ensure + tmpfile.close + tmpfile.unlink + end if output msg += "\nOutput is:\n#{output}" end