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

Host files are stripped of comments on Windows #51

Open
jd4u opened this issue Dec 3, 2022 · 12 comments
Open

Host files are stripped of comments on Windows #51

jd4u opened this issue Dec 3, 2022 · 12 comments

Comments

@jd4u
Copy link

jd4u commented Dec 3, 2022

goodhosts version 1.1.4 with vagrant 2.3.0 an vbox 6.1.38 (Windows 10)

Today upgraded from 1.1.1 to 1.1.4 and got the issue.

Issue: goodhosts auto-cleans hosts file and removes all comments

  • The issue made me loss multiple project mappings in hosts file that were commented.

  • In my case all the comments of hosts file is removed!!! and multiple records of each ip is created as single record....

  • Normally while changing user files, a copy must be created as a good practice...

Below is in the readme... That suggest goodhosts is not cleaning hosts file by default !!!! But not having the line in Vagrantfile, it cleans the hosts file. The plugin assumes total control of the hosts file of machine that runs it...!!!

==================
Disable file hosts clean

If you want /etc/hosts file cleaned add in your VagrantFile:

config.goodhosts.disable_clean = false

==================

@jd4u
Copy link
Author

jd4u commented Dec 3, 2022

This may be bug or wrong approach.

@jd4u
Copy link
Author

jd4u commented Dec 3, 2022

  • The issue happens while halting process too. (this is without having config.goodhosts.disable_clean config in Vagrantfile)
  • Inline comments are kept. Comments starting with line are removed...
  • After adding config.goodhosts.disable_clean = false, the clean is happening in up and halt process
  • After changing config.goodhosts.disable_clean = true, the clean is happening in up and halt process

@jd4u jd4u changed the title With wrong defaults goodhosts assumes complete machine control With wrong defaults goodhosts assumes complete hosts file control Dec 3, 2022
@jd4u
Copy link
Author

jd4u commented Dec 3, 2022

In all of the below cases, hosts file is cleaned....

1] without adding config.goodhosts.disable_clean in Vagrantfile

[vagrant-goodhosts] Command for CLI: 'Start-Process 'C:/Users/Username/.vagrant.d/gems/2.7.6/gems/vagrant-goodhosts-1.1.4/lib/vagrant-goodhosts/bundle/cli.exe' -ArgumentList "add","192.168.50.4","vvv.test project1.test project2.test" -Verb RunAs'
[vagrant-goodhosts] Command for CLI: 'Start-Process 'C:/Users/Username/.vagrant.d/gems/2.7.6/gems/vagrant-goodhosts-1.1.4/lib/vagrant-goodhosts/bundle/cli.exe' -ArgumentList "remove","192.168.50.4","vvv.test project1.test project2.test" -Verb RunAs'

2] Adding config.goodhosts.disable_clean=true in Vagrantfile

[vagrant-goodhosts] Command for CLI: 'Start-Process 'C:/Users/Username/.vagrant.d/gems/2.7.6/gems/vagrant-goodhosts-1.1.4/lib/vagrant-goodhosts/bundle/cli.exe' -ArgumentList "add","192.168.50.4","vvv.test project1.test project2.test" -Verb RunAs'
[vagrant-goodhosts] Command for CLI: 'Start-Process 'C:/Users/Username/.vagrant.d/gems/2.7.6/gems/vagrant-goodhosts-1.1.4/lib/vagrant-goodhosts/bundle/cli.exe' -ArgumentList "remove","192.168.50.4","vvv.test project1.test project2.test" -Verb RunAs'

3] Adding config.goodhosts.disable_clean=false in Vagrantfile

[vagrant-goodhosts] Command for CLI: 'Start-Process 'C:/Users/Username/.vagrant.d/gems/2.7.6/gems/vagrant-goodhosts-1.1.4/lib/vagrant-goodhosts/bundle/cli.exe' -ArgumentList "add","--clean","192.168.50.4","vvv.test project1.test project2.test" -Verb RunAs'
[vagrant-goodhosts] Command for CLI: 'Start-Process 'C:/Users/Username/.vagrant.d/gems/2.7.6/gems/vagrant-goodhosts-1.1.4/lib/vagrant-goodhosts/bundle/cli.exe' -ArgumentList "remove","--clean","192.168.50.4","vvv.test project1.test project2.test" -Verb RunAs'

@jd4u
Copy link
Author

jd4u commented Dec 4, 2022

The issue seems to be in goodhosts/cli project. With or without "--clean" flag, cli is performing clean process.

The cli project seems to be handling bool value incorrectly. Explicitly setting default bool value may help.

@jd4u
Copy link
Author

jd4u commented Dec 4, 2022

I wish @tomjn you find resolution soon, I see you have already found a sound pointer.

@tomjn , above all, I see management of hosts file on development machine, which is part of the OS/System components, should not be a task of any developer tools or library. Windows correctly provided UAC to disallow/prevent such actions.

Building capability in a lib is one aspect. But the enforcing a new design using that can cause lots of problem for users.
( Earlier approach of adding and removing one line to hosts file was working well and is enough!! )

VVV shall have full control within the development environment managed by it. But shall not touch the development machine components.

I hope you can understand, visualize and coordinate the design changes required.

JD

@tomjn
Copy link
Contributor

tomjn commented Dec 4, 2022 via email

@Mte90
Copy link
Member

Mte90 commented Dec 5, 2022

The issue was fixed in VVV Varying-Vagrant-Vagrants/VVV@bd20353

@Mte90 Mte90 closed this as completed Dec 5, 2022
@tomjn tomjn reopened this Dec 5, 2022
@tomjn
Copy link
Contributor

tomjn commented Dec 5, 2022

@Mte90 it wasn't, the issue is not cleaning, it's a Windows specific issue and it happens regardless of wether --clean is present or not, re-read #51 (comment)

@tomjn
Copy link
Contributor

tomjn commented Dec 5, 2022

This is much more likely to be a part of the library used by this CLI: goodhosts/hostsfile#40

@Mte90 Mte90 changed the title With wrong defaults goodhosts assumes complete hosts file control Windows issues with the clean feature Dec 5, 2022
@Mte90
Copy link
Member

Mte90 commented Dec 5, 2022

I changed the ticket name as it wasn't clear to me what was the issue.

@tomjn tomjn changed the title Windows issues with the clean feature Host files are stripped of comments on Windows Dec 5, 2022
@YouJiacheng
Copy link
Contributor

Yes. goodhosts will remove comments which might be useful for other application.
But this should be an issue of goodhosts/hostsfile. I think this issue can be closed and tracked in goodhosts/hostsfile#40

@tomjn
Copy link
Contributor

tomjn commented Dec 5, 2022

we'd still need to perform a release with any changes made in the library and CLI so this needs to be kept open, and there's still the chance the issue is elsewhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants