Method: ChefConfig::PathHelper.canonical_path

Defined in:
lib/chef-config/path_helper.rb

.canonical_path(path, add_prefix = true, windows: ChefUtils.windows?) ⇒ Object

Produces a comparable path.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/chef-config/path_helper.rb', line 113

def self.canonical_path(path, add_prefix = true, windows: ChefUtils.windows?)
  # First remove extra separators and resolve any relative paths
  abs_path = File.absolute_path(path)

  if windows
    # Add the \\?\ API prefix on Windows unless add_prefix is false
    # Downcase on Windows where paths are still case-insensitive
    abs_path.gsub!(::File::SEPARATOR, path_separator(windows: windows))
    if add_prefix && abs_path !~ /^\\\\?\\/
      abs_path.insert(0, "\\\\?\\")
    end

    abs_path.downcase!
  end

  abs_path
end