From 4bf6dc57432014f6c01b099d39c48cacb2038087 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 17 Jul 2013 10:48:39 -0700 Subject: [PATCH] Method for getting the case-correct path of a path [GH-1202] --- lib/vagrant/util/platform.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 792faa18b..a0902dd2c 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -56,6 +56,32 @@ module Vagrant return !File.file?(File.join(tmp_dir, "file")) end + # This expands the path and ensures proper casing of each part + # of the path. + def fs_real_path(path) + path = Pathname.new(File.expand_path(path)) + raise "Path must exist for path expansion" 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 + # Returns a boolean noting whether the terminal supports color. # output. def terminal_supports_colors?