From 0c22cc45e6fe7da64f037fc2fc1556c0e967d55f Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sun, 20 Nov 2016 14:09:16 +0900 Subject: cask: Call Tempfile#close(true) with the choices file to ensure it deleted --- Library/Homebrew/cask/lib/hbc/artifact/pkg.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'Library/Homebrew/cask/lib') diff --git a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb index cede9f4d5..fffb10cae 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb @@ -54,17 +54,25 @@ module Hbc ] args << "-verboseR" if Hbc.verbose args << "-allowUntrusted" if pkg_install_opts :allow_untrusted - if pkg_install_opts :choices - choices_file = choices_xml - args << "-applyChoiceChangesXML" << choices_file.path + with_choices_file pkg_install_opts(:choices) do |choices_path| + args << "-applyChoiceChangesXML" << choices_path if choices_path + @command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true) end - @command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true) end - def choices_xml - file = Tempfile.open(["", ".xml"]) - file.write Plist::Emit.dump(pkg_install_opts(:choices)) - file + def with_choices_file(choices) + unless choices + yield nil + return + end + + begin + file = Tempfile.new(["choices", ".xml"]) + file.write Plist::Emit.dump(choices) + yield file.path + ensure + file.close(true) + end end end end -- cgit v1.2.3