diff --git a/lib/vagrant/actions/box/unpackage.rb b/lib/vagrant/actions/box/unpackage.rb index 7b257789a..7c67a112c 100644 --- a/lib/vagrant/actions/box/unpackage.rb +++ b/lib/vagrant/actions/box/unpackage.rb @@ -13,6 +13,13 @@ module Vagrant end end + def rescue(exception) + if File.directory?(box_dir) + logger.info "An error occurred, rolling back box unpackaging..." + FileUtils.rm_rf(box_dir) + end + end + def setup_box_dir if File.directory?(box_dir) error_and_exit(<<-msg) diff --git a/test/vagrant/actions/box/unpackage_test.rb b/test/vagrant/actions/box/unpackage_test.rb index b8e132ad9..1523b3399 100644 --- a/test/vagrant/actions/box/unpackage_test.rb +++ b/test/vagrant/actions/box/unpackage_test.rb @@ -28,6 +28,27 @@ class UnpackageBoxActionTest < Test::Unit::TestCase end end + context "rescuing" do + setup do + File.stubs(:directory?).returns(false) + FileUtils.stubs(:rm_rf) + + @box_dir = mock("foo") + @action.stubs(:box_dir).returns(@box_dir) + end + + should "do nothing if a directory doesn't exist" do + FileUtils.expects(:rm_rf).never + @action.rescue(nil) + end + + should "remove the box directory if it exists" do + File.expects(:directory?).returns(true) + FileUtils.expects(:rm_rf).with(@box_dir).once + @action.rescue(nil) + end + end + context "box directory" do should "return the runner directory" do result = mock("object")