Box actions clean up the temporary file after unpackaging
This commit is contained in:
parent
c7e21a0c94
commit
5b68f3dd10
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue