diff --git a/lib/vagrant/env.rb b/lib/vagrant/env.rb index 0c70ec2ce..83fb4d5ff 100644 --- a/lib/vagrant/env.rb +++ b/lib/vagrant/env.rb @@ -89,7 +89,10 @@ module Vagrant def load_root_path!(path=nil) path ||= Pathname.new(Dir.pwd) - return false if path.to_s == '/' + # Stop if we're at the root. 2nd regex matches windows drives + # such as C:. and Z:. Portability of this check will need to be + # researched. + return false if path.to_s == '/' || path.to_s =~ /^[A-Z]:\.$/ file = "#{path}/#{ROOTFILE_NAME}" if File.exist?(file) diff --git a/test/vagrant/env_test.rb b/test/vagrant/env_test.rb index 7766f5f6d..75b2da9a6 100644 --- a/test/vagrant/env_test.rb +++ b/test/vagrant/env_test.rb @@ -218,11 +218,16 @@ class EnvTest < Test::Unit::TestCase assert !Vagrant::Env.load_root_path!(paths.first) end - should "should return false if not found" do + should "return false if not found" do path = Pathname.new("/") assert !Vagrant::Env.load_root_path!(path) end + should "return false if not found on windows-style root" do + path = Pathname.new("C:.") + assert !Vagrant::Env.load_root_path!(path) + end + should "should set the path for the rootfile" do path = "/foo" File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(true)