Windows root path checking. Interim solution.

This commit is contained in:
Mitchell Hashimoto 2010-03-09 12:33:54 -08:00
parent bee84a9cb0
commit 6c5ddcdf8d
2 changed files with 10 additions and 2 deletions

View File

@ -89,7 +89,10 @@ module Vagrant
def load_root_path!(path=nil) def load_root_path!(path=nil)
path ||= Pathname.new(Dir.pwd) 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}" file = "#{path}/#{ROOTFILE_NAME}"
if File.exist?(file) if File.exist?(file)

View File

@ -218,11 +218,16 @@ class EnvTest < Test::Unit::TestCase
assert !Vagrant::Env.load_root_path!(paths.first) assert !Vagrant::Env.load_root_path!(paths.first)
end end
should "should return false if not found" do should "return false if not found" do
path = Pathname.new("/") path = Pathname.new("/")
assert !Vagrant::Env.load_root_path!(path) assert !Vagrant::Env.load_root_path!(path)
end 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 should "should set the path for the rootfile" do
path = "/foo" path = "/foo"
File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(true) File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(true)