From bda25ac0872a101b59d8ab473218ff0f14bb7433 Mon Sep 17 00:00:00 2001 From: Raphaƫl Pinson Date: Fri, 18 Jan 2013 21:29:29 +0100 Subject: validate_cmd: Make sure tmpfile is always closed and unlinked --- lib/puppet/parser/functions/validate_cmd.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/puppet/parser/functions/validate_cmd.rb') 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 -- cgit v1.2.3