diff --git a/lib/vagrant/action/box/unpackage.rb b/lib/vagrant/action/box/unpackage.rb index 79f832ab5..c7a2b0cf7 100644 --- a/lib/vagrant/action/box/unpackage.rb +++ b/lib/vagrant/action/box/unpackage.rb @@ -25,11 +25,9 @@ module Vagrant decompress @app.call(@env) - - cleanup if @env.error? end - def cleanup + def recover(env) if File.directory?(box_directory) FileUtils.rm_rf(box_directory) end diff --git a/test/vagrant/action/box/unpackage_test.rb b/test/vagrant/action/box/unpackage_test.rb index d66a76b80..022ffa421 100644 --- a/test/vagrant/action/box/unpackage_test.rb +++ b/test/vagrant/action/box/unpackage_test.rb @@ -21,7 +21,6 @@ class UnpackageBoxActionTest < Test::Unit::TestCase @instance.expects(:setup_box_directory).in_sequence(seq).returns(true) @instance.expects(:decompress).in_sequence(seq) @app.expects(:call).with(@env) - @instance.expects(:cleanup).never @instance.call(@env) end @@ -29,18 +28,6 @@ class UnpackageBoxActionTest < Test::Unit::TestCase @instance.expects(:setup_box_directory).returns(false) @instance.expects(:decompress).never @app.expects(:call).never - @instance.expects(:cleanup).never - @instance.call(@env) - end - - should "cleanup if there was an error" do - @env.error!(:foo) - - seq = sequence("sequence") - @instance.expects(:setup_box_directory).in_sequence(seq).returns(true) - @instance.expects(:decompress).in_sequence(seq) - @app.expects(:call).with(@env) - @instance.expects(:cleanup).once @instance.call(@env) end end @@ -54,13 +41,13 @@ class UnpackageBoxActionTest < Test::Unit::TestCase should "do nothing if not a directory" do FileUtils.expects(:rm_rf).never - @instance.cleanup + @instance.recover(nil) end should "remove the directory if exists" do File.expects(:directory?).with(@instance.box_directory).once.returns(true) FileUtils.expects(:rm_rf).with(@instance.box_directory).once - @instance.cleanup + @instance.recover(nil) end end