customink-webops / hostsfile

Easily manage your hosts file with Chef
Apache License 2.0
155 stars 82 forks source link

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

Open dwkerwin opened 7 years ago

dwkerwin commented 7 years ago

I've been using this for a while, and even though on Windows when you view the hosts file everything appears to be on one line, it has been working. I recently noticed that if you have a lot of host aliases on the same machine the ones at the end aren't honored, and then discovered that there is a limit on Windows of 9 aliases per line. So this small fix uses the environment specific newline terminator, so "\r\n" for Windows and "\n" for all other environments.

dwkerwin commented 7 years ago

The first commit didn't completely solve the problem. Line terminations were right but it was still flattening the hosts to a single line. In the use case where you have multiple (> 10) hostnames which you want to all point to a single IP (typically 127.0.0.1), this exceeds the Windows limit of 9 per line. This change prevents this flattening for Windows while continuing to be idempotent, preventing duplicate entries by hostname rather than IP address.

dwkerwin commented 7 years ago

It looks like the Travis CI errors are unrelated to my changes. Please let me know if this is not the case or how I could help.