validate_cmd: Make sure tmpfile is always closed and unlinked
This commit is contained in:
parent
f6a63eeafa
commit
bda25ac087
1 changed files with 8 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue