]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
validate_cmd: Make sure tmpfile is always closed and unlinked
authorRaphaël Pinson <raphael.pinson@camptocamp.com>
Fri, 18 Jan 2013 20:29:29 +0000 (21:29 +0100)
committerRaphaël Pinson <raphael.pinson@camptocamp.com>
Fri, 18 Jan 2013 21:01:03 +0000 (22:01 +0100)
lib/puppet/parser/functions/validate_cmd.rb

index e7793c3a941a7cc87ed1c780bbc5b8cebbb08c8f..00fe1ae2b9ad251f46c5e9a5e64ac961ca6e4a47 100644 (file)
@@ -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