diff options
author | Raphaël Pinson <raphael.pinson@camptocamp.com> | 2013-01-18 21:29:29 +0100 |
---|---|---|
committer | Raphaël Pinson <raphael.pinson@camptocamp.com> | 2013-01-18 22:01:03 +0100 |
commit | bda25ac0872a101b59d8ab473218ff0f14bb7433 (patch) | |
tree | 1b872cd48d22c075808b7a6a06b4c6a72a4dc51c /lib/puppet | |
parent | f6a63eeafa89d01a700a7eb6ba1217034535b50b (diff) | |
download | puppet-stdlib-bda25ac0872a101b59d8ab473218ff0f14bb7433.tar.gz puppet-stdlib-bda25ac0872a101b59d8ab473218ff0f14bb7433.tar.bz2 |
validate_cmd: Make sure tmpfile is always closed and unlinked
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/parser/functions/validate_cmd.rb | 13 |
1 files changed, 8 insertions, 5 deletions
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 |