CleanMachineFolder won't run if the folder is < 10 characters. Small safeguard againt unwanted rm-rfs.

This commit is contained in:
Mitchell Hashimoto 2010-07-14 21:03:58 -07:00
parent 3c1aac7ff5
commit 7de7982214
2 changed files with 12 additions and 1 deletions

View File

@ -19,6 +19,12 @@ module Vagrant
def clean_machine_folder
folder = File.join(VirtualBox::Global.global.system_properties.default_machine_folder, "*")
# Small safeguard against potentially unwanted rm-rf, since the default
# machine folder will typically always be greater than 10 characters long.
# For users with it < 10, out of luck?
return if folder.length < 10
Dir[folder].each do |f|
next unless File.directory?(f)

View File

@ -19,7 +19,7 @@ class CleanMachineFolderVMActionTest < Test::Unit::TestCase
context "cleaning the folder" do
setup do
@machine_folder = "foo"
@machine_folder = "/foo/bar/baz"
@folder = File.join(@machine_folder, "*")
VirtualBox::Global.global.system_properties.stubs(:default_machine_folder).returns(@machine_folder)
File.stubs(:file?).returns(true)
@ -73,5 +73,10 @@ class CleanMachineFolderVMActionTest < Test::Unit::TestCase
@instance.clean_machine_folder
end
should "do nothing if folder is < 10 characters" do
VirtualBox::Global.global.system_properties.stubs(:default_machine_folder).returns("foo")
Dir.expects(:[]).never
end
end
end