From 6c5ddcdf8d68a362e02f00420459b33982bb4cc2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 9 Mar 2010 12:33:54 -0800 Subject: [PATCH] Windows root path checking. Interim solution. --- lib/vagrant/env.rb | 5 ++++- test/vagrant/env_test.rb | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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)