Method: ChefConfig::PathHelper.validate_path

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

.validate_path(path, windows: ChefUtils.windows?) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef-config/path_helper.rb', line 73

def self.validate_path(path, windows: ChefUtils.windows?)
  if windows
    unless printable?(path)
      msg = "Path '#{path}' contains non-printable characters. Check that backslashes are escaped with another backslash (e.g. C:\\\\Windows) in double-quoted strings."
      ChefConfig.logger.error(msg)
      raise ChefConfig::InvalidPath, msg
    end

    if windows_max_length_exceeded?(path)
      ChefConfig.logger.trace("Path '#{path}' is longer than #{WIN_MAX_PATH}, prefixing with'\\\\?\\'")
      path.insert(0, "\\\\?\\")
    end
  end

  path
end