diff --git a/lib/vagrant/actions/box/download.rb b/lib/vagrant/actions/box/download.rb index ed1bfc204..3c5a5e448 100644 --- a/lib/vagrant/actions/box/download.rb +++ b/lib/vagrant/actions/box/download.rb @@ -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| diff --git a/lib/vagrant/actions/box/unpackage.rb b/lib/vagrant/actions/box/unpackage.rb index 14871cb3c..67a3c65d0 100644 --- a/lib/vagrant/actions/box/unpackage.rb +++ b/lib/vagrant/actions/box/unpackage.rb @@ -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 diff --git a/test/vagrant/actions/box/download_test.rb b/test/vagrant/actions/box/download_test.rb index 6af5b00ca..0697581ff 100644 --- a/test/vagrant/actions/box/download_test.rb +++ b/test/vagrant/actions/box/download_test.rb @@ -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") diff --git a/test/vagrant/actions/box/unpackage_test.rb b/test/vagrant/actions/box/unpackage_test.rb index 1c31c3f3d..b8e132ad9 100644 --- a/test/vagrant/actions/box/unpackage_test.rb +++ b/test/vagrant/actions/box/unpackage_test.rb @@ -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