Box actions clean up the temporary file after unpackaging

This commit is contained in:
Mitchell Hashimoto 2010-02-22 22:42:31 -08:00
parent c7e21a0c94
commit 5b68f3dd10
4 changed files with 37 additions and 2 deletions

View File

@ -14,6 +14,11 @@ module Vagrant
end
end
def after_unpackage
logger.info "Cleaning up tempfile..."
File.unlink(@runner.temp_path) if @runner.temp_path && File.exist?(@runner.temp_path)
end
def with_tempfile
logger.info "Creating tempfile for storing box file..."
Tempfile.open(BASENAME, Env.tmp_path) do |tempfile|

View File

@ -5,8 +5,10 @@ module Vagrant
TAR_OPTIONS = [File::RDONLY, 0644, Tar::GNU]
def execute!
setup_box_dir
decompress
@runner.invoke_around_callback(:unpackage) do
setup_box_dir
decompress
end
end
def setup_box_dir

View File

@ -50,6 +50,25 @@ class DownloadBoxActionTest < Test::Unit::TestCase
end
end
context "after unpackaging" do
setup do
@temp_path = "foo"
@runner.stubs(:temp_path).returns(@temp_path)
File.stubs(:exist?).returns(true)
end
should "delete the temporary file if it exists" do
File.expects(:unlink).with(@temp_path).once
@action.after_unpackage
end
should "not delete anything if it doesn't exist" do
File.stubs(:exist?).returns(false)
File.expects(:unlink).never
@action.after_unpackage
end
end
context "copying URI file" do
setup do
@tempfile = mock("tempfile")

View File

@ -11,12 +11,21 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
end
context "executing" do
setup do
@runner.stubs(:invoke_around_callback).yields
end
should "execute the proper actions in the proper order" do
exec_seq = sequence("exec_seq")
@action.expects(:setup_box_dir).in_sequence(exec_seq)
@action.expects(:decompress).in_sequence(exec_seq)
@action.execute!
end
should "execute it in a around block" do
@runner.expects(:invoke_around_callback).with(:unpackage).once
@action.execute!
end
end
context "box directory" do