Fixes #9593: Ensure temp dir for package command is cleaned up

Prior to this commit, the package actions would create a temp dir in
the process of packaging and compressing a Vagrant box. This commit
ensures that the temp dir is removed once the command has completed so
that it doesn't leave around lots of temp directories.
This commit is contained in:
Brian Cain 2018-12-04 11:07:53 -08:00
parent 153101d21b
commit 86e2b78997
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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