From e2ec46bb4d178e8f53685fa9979c6532bef12abf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 15 Jan 2014 11:40:53 -0800 Subject: [PATCH] core: environment tests passing on Windows --- lib/vagrant/environment.rb | 5 ++-- lib/vagrant/util/platform.rb | 37 +++++++++++++-------------- test/unit/vagrant/environment_test.rb | 10 +++----- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index dacdaa579..2423e8d44 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -598,9 +598,8 @@ module Vagrant # # @return [Pathname] def setup_home_path - @home_path = Pathname.new(File.expand_path(@home_path || - ENV["VAGRANT_HOME"] || - Vagrant.user_data_path)) + @home_path = Util::Platform.fs_real_path( + @home_path || ENV["VAGRANT_HOME"] || Vagrant.user_data_path) @logger.info("Home path: #{@home_path}") # Setup the list of child directories that need to be created if they diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 120db6986..489ef63ff 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -61,6 +61,24 @@ module Vagrant def fs_real_path(path) path = Pathname.new(File.expand_path(path)) + if path.exist? && !fs_case_sensitive? + # Build up all the parts of the path + original = [] + while !path.root? + original.unshift(path.basename.to_s) + path = path.parent + end + + # Traverse each part and join it into the resulting path + original.each do |single| + Dir.entries(path).each do |entry| + if entry.downcase == single.downcase + path = path.join(entry) + end + end + end + end + if windows? # Fix the drive letter to be uppercase. path = path.to_s @@ -71,25 +89,6 @@ module Vagrant path = Pathname.new(path) end - return path if !path.exist? - return path if fs_case_sensitive? - - # Build up all the parts of the path - original = [] - while !path.root? - original.unshift(path.basename.to_s) - path = path.parent - end - - # Traverse each part and join it into the resulting path - original.each do |single| - Dir.entries(path).each do |entry| - if entry.downcase == single.downcase - path = path.join(entry) - end - end - end - path end diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index b3c863d93..d686c09ce 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -230,19 +230,15 @@ describe Vagrant::Environment do end context "default home path" do - before :each do - Vagrant::Util::Platform.stub(:windows? => false) - end - it "is set to '~/.vagrant.d' by default" do - expected = Pathname.new(File.expand_path("~/.vagrant.d")) + expected = Vagrant::Util::Platform.fs_real_path("~/.vagrant.d") described_class.new.home_path.should == expected end it "is set to '~/.vagrant.d' if on Windows but no USERPROFILE" do Vagrant::Util::Platform.stub(:windows? => true) - expected = Pathname.new(File.expand_path("~/.vagrant.d")) + expected = Vagrant::Util::Platform.fs_real_path("~/.vagrant.d") with_temp_env("USERPROFILE" => nil) do described_class.new.home_path.should == expected @@ -253,7 +249,7 @@ describe Vagrant::Environment do Vagrant::Util::Platform.stub(:windows? => true) Dir.mktmpdir do |dir| - expected = Pathname.new(File.expand_path("#{dir}/.vagrant.d")) + expected = Vagrant::Util::Platform.fs_real_path("#{dir}/.vagrant.d") with_temp_env("USERPROFILE" => dir) do described_class.new.home_path.should == expected