diff --git a/plugins/commands/package/command.rb b/plugins/commands/package/command.rb index 947e5f222..4d468b533 100644 --- a/plugins/commands/package/command.rb +++ b/plugins/commands/package/command.rb @@ -87,7 +87,10 @@ module VagrantPlugins acc end - vm.action(:package, opts) + env = vm.action(:package, opts) + temp_dir = env["export.temp_dir"] + ensure + FileUtils.rm_rf(temp_dir) if temp_dir end end end diff --git a/test/unit/plugins/commands/package/command_test.rb b/test/unit/plugins/commands/package/command_test.rb index 49a5fbe89..7b289bd1e 100644 --- a/test/unit/plugins/commands/package/command_test.rb +++ b/test/unit/plugins/commands/package/command_test.rb @@ -109,6 +109,24 @@ describe VagrantPlugins::CommandPackage::Command do end end end + end + describe "#package_vm" do + context "calling the package action" do + let(:options) { {output: "test.box"} } + let(:expected_options) { {"package.output"=>"test.box"} } + let(:machine) { double("machine") } + let(:tmp_dir) { "/home/user/.vagrant.d/tmp/vagrant-package" } + let(:env) { {"export.temp_dir"=>tmp_dir} } + + it "ensures that the package tmp dir is cleaned up" do + allow(FileUtils).to receive(:rm_rf).and_return(true) + allow(machine).to receive(:action).with(:package, expected_options). + and_return(env) + + expect(FileUtils).to receive(:rm_rf).with(tmp_dir) + package_command.send(:package_vm, machine, options) + end + end end end