cask: Call Tempfile#close(true) with the choices file to ensure it deleted

This commit is contained in:
Kaito Udagawa 2016-11-20 14:09:16 +09:00
parent 2807202103
commit 0c22cc45e6
2 changed files with 19 additions and 9 deletions

View File

@ -54,17 +54,25 @@ module Hbc
] ]
args << "-verboseR" if Hbc.verbose args << "-verboseR" if Hbc.verbose
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted args << "-allowUntrusted" if pkg_install_opts :allow_untrusted
if pkg_install_opts :choices with_choices_file pkg_install_opts(:choices) do |choices_path|
choices_file = choices_xml args << "-applyChoiceChangesXML" << choices_path if choices_path
args << "-applyChoiceChangesXML" << choices_file.path @command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)
end end
@command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)
end end
def choices_xml def with_choices_file(choices)
file = Tempfile.open(["", ".xml"]) unless choices
file.write Plist::Emit.dump(pkg_install_opts(:choices)) yield nil
file 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 end
end end

View File

@ -60,7 +60,9 @@ describe Hbc::Artifact::Pkg do
</plist> </plist>
EOS EOS
file.stubs path: Pathname.new("/tmp/choices.xml") 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")]) 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 shutup do