Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for CRLF on windows to avoid max aliases per line issue #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions libraries/manipulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def update(options = {})
#
# @param (see #add)
def append(options = {})
if entry = find_entry_by_ip_address(options[:ip_address])
if entry = not(node['platform_family'] == 'windows') && find_entry_by_ip_address(options[:ip_address])
hosts = normalize(entry.hostname, entry.aliases, options[:hostname], options[:aliases])
entry.hostname = hosts.shift
entry.aliases = hosts
Expand Down Expand Up @@ -217,7 +217,14 @@ def new_content
entries = hostsfile_header
entries += unique_entries.map(&:to_line)
entries << ''
entries.join("\n")
# windows has a limit of 9 host aliases per line, so without proper line
# endings, additional host entries wind up being ignored
case node['platform_family']
when 'windows'
entries.join("\r\n")
else
entries.join("\n")
end
end

# The current sha of the system hostsfile.
Expand All @@ -244,7 +251,8 @@ def normalize(*things)
# @return [Array]
# the sorted list of entires that are unique
def unique_entries
entries = Hash[*@entries.map { |entry| [entry.ip_address, entry] }.flatten].values
is_windows = node['platform_family'] == 'windows'
entries = Hash[*@entries.map { |entry| [is_windows ? entry.hostname : entry.ip_address, entry] }.flatten].values
entries.sort_by { |e| [-e.priority.to_i, e.hostname.to_s] }
end

Expand Down