diff --git a/lib/vagrant/action/box/unpackage.rb b/lib/vagrant/action/box/unpackage.rb index 00f5bbbb3..49be2ce6b 100644 --- a/lib/vagrant/action/box/unpackage.rb +++ b/lib/vagrant/action/box/unpackage.rb @@ -31,7 +31,7 @@ module Vagrant end def recover(env) - if File.directory?(box_directory) + if box_directory && File.directory?(box_directory) FileUtils.rm_rf(box_directory) end end diff --git a/test/vagrant/action/box/unpackage_test.rb b/test/vagrant/action/box/unpackage_test.rb index feafb556d..3082a21d5 100644 --- a/test/vagrant/action/box/unpackage_test.rb +++ b/test/vagrant/action/box/unpackage_test.rb @@ -26,6 +26,13 @@ class UnpackageBoxActionTest < Test::Unit::TestCase FileUtils.stubs(:rm_rf) end + should "do nothing if box directory is not set" do + @instance.stubs(:box_directory).returns(nil) + File.expects(:directory?).never + FileUtils.expects(:rm_rf).never + @instance.recover(nil) + end + should "do nothing if not a directory" do FileUtils.expects(:rm_rf).never @instance.recover(nil)