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
|
||||||
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
|
def with_tempfile
|
||||||
logger.info "Creating tempfile for storing box file..."
|
logger.info "Creating tempfile for storing box file..."
|
||||||
Tempfile.open(BASENAME, Env.tmp_path) do |tempfile|
|
Tempfile.open(BASENAME, Env.tmp_path) do |tempfile|
|
||||||
|
|
|
@ -5,8 +5,10 @@ module Vagrant
|
||||||
TAR_OPTIONS = [File::RDONLY, 0644, Tar::GNU]
|
TAR_OPTIONS = [File::RDONLY, 0644, Tar::GNU]
|
||||||
|
|
||||||
def execute!
|
def execute!
|
||||||
setup_box_dir
|
@runner.invoke_around_callback(:unpackage) do
|
||||||
decompress
|
setup_box_dir
|
||||||
|
decompress
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_box_dir
|
def setup_box_dir
|
||||||
|
|
|
@ -50,6 +50,25 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
context "copying URI file" do
|
||||||
setup do
|
setup do
|
||||||
@tempfile = mock("tempfile")
|
@tempfile = mock("tempfile")
|
||||||
|
|
|
@ -11,12 +11,21 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
context "executing" do
|
context "executing" do
|
||||||
|
setup do
|
||||||
|
@runner.stubs(:invoke_around_callback).yields
|
||||||
|
end
|
||||||
|
|
||||||
should "execute the proper actions in the proper order" do
|
should "execute the proper actions in the proper order" do
|
||||||
exec_seq = sequence("exec_seq")
|
exec_seq = sequence("exec_seq")
|
||||||
@action.expects(:setup_box_dir).in_sequence(exec_seq)
|
@action.expects(:setup_box_dir).in_sequence(exec_seq)
|
||||||
@action.expects(:decompress).in_sequence(exec_seq)
|
@action.expects(:decompress).in_sequence(exec_seq)
|
||||||
@action.execute!
|
@action.execute!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "execute it in a around block" do
|
||||||
|
@runner.expects(:invoke_around_callback).with(:unpackage).once
|
||||||
|
@action.execute!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "box directory" do
|
context "box directory" do
|
||||||
|
|
Loading…
Reference in New Issue