Merge pull request #10479 from briancain/ensure-tmp-dir-cleanup-package-cmd

Fixes #9593: Ensure temp dir for package command is cleaned up
This commit is contained in:
Brian Cain 2018-12-06 15:08:18 -08:00 committed by GitHub
commit 119f82d826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -87,7 +87,10 @@ module VagrantPlugins
acc acc
end 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 end
end end

View File

@ -109,6 +109,24 @@ describe VagrantPlugins::CommandPackage::Command do
end end
end 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
end end