-
Notifications
You must be signed in to change notification settings - Fork 129
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
Hosts entries appended incorrectly to hosts file on Mac #141
Comments
@Kellman3000 Can you test with version 1.1.0? If it is still an issue I will find out how to fix it. |
I'm seeing this issue with 1.1.1.160 on Mac High Sierra. |
I'm also seeing this issue with 1.1.1.160 on Mac High Sierra (10.13.5) |
Also seeing this with 1.1.1.160 on Mac High Sierra. |
I would think it wouldn't be an issue unless there needs to be a |
I think I've figured out why this is happening. That code you linked to is never actually invoked on most systems, because the hosts file is owned by root and not writeable. Instead, this line writes to the hosts file without a newline: https://github.com/cogitatio/vagrant-hostsupdater/blob/bdfa1c70bb808c848f7012322d4f5907ca83d84c/lib/vagrant-hostsupdater/HostsUpdater.rb#L143 FYI, this is easily reproducible on a standard Linux/Mac OS by saving your hosts file without a new line at the end, and then running vagrant up with hostsupdater enabled. I haven't quite figured out how to solve this. The problem is that if you fix the conditional to actually work as intended, your hosts file quickly blows up with a whole bunch of trailing newlines. I'm not sure the best way to prevent those. |
I've opened a PR to fix this. Note that this may actually be a dangerous bug. When vagrant hostsupdater appends to a hosts file without a newline, its output gets concatenated with the last line of the host file. Then when hostsupdater removes its lines, it would probably remove what used to be the last line of the file. That's a pretty destructive maneuver 😨 |
I'll take a look at #165 within the upcoming week. |
@cgsmith actually I just confirmed via a test that Vagrant Hostsupdater will destructively modify your hosts file if it does not contain a trailing newline. Easy to test, just add a line to the end of your hosts file that you don't care about and save it without a newline: Now run Now run |
I see what you mean. Thanks for the clarification |
Using 1.0.2 on a Mac, I found that if there is no blank line at the end of the hosts file, the plugin simply appends to the last line, rather than adding a new line. If there is a blank line already there, it appends to the blank line. MacOS 10.12.6
The text was updated successfully, but these errors were encountered: