Class: Vagrant::Util::Platform
- Inherits:
-
Object
- Object
- Vagrant::Util::Platform
- Defined in:
- lib/vagrant/util/platform.rb
Overview
This class just contains some platform checking code.
Class Method Summary collapse
- .cygwin? ⇒ Boolean
-
.cygwin_windows_path(path) ⇒ String
This takes any path and converts it to a full-length Windows path on Windows machines in Cygwin.
-
.fs_case_sensitive? ⇒ Boolean
This checks if the filesystem is case sensitive.
-
.fs_real_path(path) ⇒ Object
This expands the path and ensures proper casing of each part of the path.
- .platform ⇒ Object
-
.terminal_supports_colors? ⇒ Boolean
Returns a boolean noting whether the terminal supports color.
- .windows? ⇒ Boolean
Class Method Details
.cygwin? ⇒ Boolean
11 12 13 14 15 16 |
# File 'lib/vagrant/util/platform.rb', line 11 def cygwin? return true if ENV["VAGRANT_DETECTED_OS"] && ENV["VAGRANT_DETECTED_OS"].downcase.include?("cygwin") platform.include?("cygwin") end |
.cygwin_windows_path(path) ⇒ String
This takes any path and converts it to a full-length Windows path on Windows machines in Cygwin.
36 37 38 39 40 41 |
# File 'lib/vagrant/util/platform.rb', line 36 def cygwin_windows_path(path) return path if !cygwin? process = Subprocess.execute("cygpath", "-w", "-l", "-a", path.to_s) process.stdout.chomp end |
.fs_case_sensitive? ⇒ Boolean
This checks if the filesystem is case sensitive. This is not a 100% correct check, since it is possible that the temporary directory runs a different filesystem than the root directory. However, this works in many cases.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant/util/platform.rb', line 47 def fs_case_sensitive? tmp_dir = Dir.mktmpdir("vagrant") tmp_file = File.join(tmp_dir, "FILE") File.open(tmp_file, "w") do |f| f.write("foo") end # The filesystem is case sensitive if the lowercased version # of the filename is NOT reported as existing. return !File.file?(File.join(tmp_dir, "file")) end |
.fs_real_path(path) ⇒ Object
This expands the path and ensures proper casing of each part of the path.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vagrant/util/platform.rb', line 61 def fs_real_path(path) path = Pathname.new(File.(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 |
.platform ⇒ Object
95 96 97 |
# File 'lib/vagrant/util/platform.rb', line 95 def platform RbConfig::CONFIG["host_os"].downcase end |
.terminal_supports_colors? ⇒ Boolean
Returns a boolean noting whether the terminal supports color. output.
87 88 89 90 91 92 93 |
# File 'lib/vagrant/util/platform.rb', line 87 def terminal_supports_colors? if windows? return ENV.has_key?("ANSICON") || cygwin? end true end |
.windows? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/vagrant/util/platform.rb', line 24 def windows? %W[mingw mswin].each do |text| return true if platform.include?(text) end false end |