From 61314c5e21cc73b0ae2a9f1a41731d6f8254a471 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 1 Oct 2010 09:20:18 -0700 Subject: [PATCH] Only check for box directory if it is set during unpackage recovery [related to GH-170] --- lib/vagrant/action/box/unpackage.rb | 2 +- test/vagrant/action/box/unpackage_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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)