From b92efdfe53ea1bfc687726880380d2a277b0a5f8 Mon Sep 17 00:00:00 2001 From: John Bender Date: Wed, 10 Mar 2010 00:30:28 -0800 Subject: [PATCH] windows root path fix --- lib/vagrant/env.rb | 8 +++----- test/vagrant/env_test.rb | 9 ++++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/vagrant/env.rb b/lib/vagrant/env.rb index c3ed1bea9..f94bd7a3c 100644 --- a/lib/vagrant/env.rb +++ b/lib/vagrant/env.rb @@ -114,12 +114,10 @@ msg end def load_root_path!(path=nil) - path ||= Pathname.new(Dir.pwd) + path = Pathname.new(File.expand_path(path || Dir.pwd)) - # 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]:\.$/ + # Stop if we're at the root. + return false if path.root? file = "#{path}/#{ROOTFILE_NAME}" if File.exist?(file) diff --git a/test/vagrant/env_test.rb b/test/vagrant/env_test.rb index bb88e52c6..909b2ba1b 100644 --- a/test/vagrant/env_test.rb +++ b/test/vagrant/env_test.rb @@ -211,7 +211,7 @@ class EnvTest < Test::Unit::TestCase context "loading the root path" do should "default the path to the pwd if nil" do @path = mock("path") - @path.stubs(:to_s).returns("/") + @path.stubs(:root?).returns(true) Pathname.expects(:new).with(Dir.pwd).returns(@path) Vagrant::Env.load_root_path!(nil) end @@ -219,7 +219,9 @@ class EnvTest < Test::Unit::TestCase should "not default the path to pwd if its not nil" do @path = mock("path") @path.stubs(:to_s).returns("/") - Pathname.expects(:new).never + File.expects(:expand_path).with(@path).returns("/") + Pathname.expects(:new).with("/").returns(@path) + @path.stubs(:root?).returns(true) Vagrant::Env.load_root_path!(@path) end @@ -244,7 +246,8 @@ class EnvTest < Test::Unit::TestCase end should "return false if not found on windows-style root" do - path = Pathname.new("C:.") + # Note the escaped back slash + path = Pathname.new("C:\\") assert !Vagrant::Env.load_root_path!(path) end