diff options
| author | Kaito Udagawa | 2016-11-20 14:09:16 +0900 |
|---|---|---|
| committer | Kaito Udagawa | 2016-11-20 14:23:55 +0900 |
| commit | 0c22cc45e6fe7da64f037fc2fc1556c0e967d55f (patch) | |
| tree | 7bd299771401f0490b5152b137b24d66e7a8ee31 /Library/Homebrew | |
| parent | 28072021031836937a01e9fd995b03995fe49443 (diff) | |
| download | brew-0c22cc45e6fe7da64f037fc2fc1556c0e967d55f.tar.bz2 | |
cask: Call Tempfile#close(true) with the choices file to ensure it deleted
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/pkg.rb | 24 | ||||
| -rw-r--r-- | Library/Homebrew/cask/test/cask/artifact/pkg_test.rb | 4 |
2 files changed, 19 insertions, 9 deletions
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 diff --git a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb b/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb index cb30c4a0a..6e10177d1 100644 --- a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb +++ b/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb @@ -60,7 +60,9 @@ describe Hbc::Artifact::Pkg do </plist> EOS file.stubs path: Pathname.new("/tmp/choices.xml") - Tempfile.expects(:open).returns(file) + file.expects(:close).with true + Tempfile.expects(:new).returns file + Hbc::FakeSystemCommand.expects_command(["/usr/bin/sudo", "-E", "--", "/usr/sbin/installer", "-pkg", @cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/", "-applyChoiceChangesXML", @cask.staged_path.join("/tmp/choices.xml")]) shutup do |
