goodhosts/cli

Goodhosts don't remove duplicates

Mte90 opened this issue · 10 comments

Mte90 commented

We are facing some issues with the vagrant plugin that when we add new hosts, they are added creating things like:

192.168.50.4 vvv vvv.test boilerplate.test woocommerce.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test boilerplate.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test tideways.vvv.test xhgui.vvv.test vvv vvv.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test src.wordpress-develop.test build.wordpress-develop.test tideways.vvv.test xhgui.vvv.test vvv vvv.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test src.wordpress-develop.test build.wordpress-develop.test tideways.vvv.test xhgui.vvv.test vvv vvv.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test src.wordpress-develop.test build.wordpress-develop.test tideways.vvv.test xhgui.vvv.test vvv vvv.test woocommerce.test 503702305c22.ngrok.io auto.test glossary.test src.wordpress-develop.test build.wordpress-develop.test tideways.vvv.test xhgui.vvv.test

hi @Mte90 ran some scenarios in my head while walking through code and im not sure how you ended up getting this result. if you look here: https://github.com/goodhosts/hostsfile/blob/master/hosts.go#L117 it skips dupes in the hostsfile library and here: https://github.com/goodhosts/cli/blob/master/cmd/add.go#L37-L43 in the cli it pulls dupes from the args passed.

even the remove call should take out dupes... any ideas how this could have happened? I'm currently at a loss.

Mte90 commented

Hi @luthermonson we saw various users of the vagrant plugin with the issue.
The plugin run add on boot and remove on halt but can happen that you turn of the host machine without turning off the virtual machine so the remove command is not executed.

The fact that identify the right ip address and enqueue them is good but is not detecting in the line that domain already exists so it is appended anyway. Maybe the issue is in the domain detection in a long line?

I think that you can do some tests with that line that I shared to you but I am here for debugging also to compile the tool if needed.

i added a clean command and ran it across your line and it improves things, perhaps we can run this before every flush in add/remove. Give it a try: https://github.com/goodhosts/cli/releases/tag/v1.0.4

PS C:\Users\luthe\goodhosts\hostsfile> goodhosts -f ./hosts clean
PS C:\Users\luthe\goodhosts\hostsfile> type hosts
192.168.50.4 503702305c22.ngrok.io auto.test boilerplate.test build.wordpress-develop.test glossary.test src.wordpress-develop.test tideways.vvv.test vvv vvv.test woocommerce.test xhgui.vvv.test

I just can't seem to get the add to not strip out dupes.

PS C:\Users\luthe\goodhosts\hostsfile> goodhosts -f ./hosts add 192.168.50.4 503702305c22.ngrok.io auto.test boilerplate.test build.wordpress-develop.test glossary.test src.wordpress-develop.test tideways.vvv.test vvv vvv.test woocommerce.test xhgui.vvv.test
hosts entry added: 192.168.50.4 vvv.test woocommerce.test auto.test build.wordpress-develop.test vvv src.wordpress-develop.test tideways.vvv.test xhgui.vvv.test 503702305c22.ngrok.io boilerplate.test glossary.test
PS C:\Users\luthe\goodhosts\hostsfile> type hosts
192.168.50.4 503702305c22.ngrok.io auto.test boilerplate.test build.wordpress-develop.test glossary.test src.wordpress-develop.test tideways.vvv.test vvv vvv.test woocommerce.test xhgui.vvv.test
Mte90 commented

Seems that clean that line rightly, this command can be executed on adding/removing?

Mte90 commented

any updates?

Sorry for delay, v1.0.5 now has all this.

Mte90 commented

Hi @luthermonson, it is not clear to me a thing.
It is possible to do the clean on adding or remove? I am trying just to optimize the thing and avoid executing 2 commands.

yes, there is a --clean or -c you can use on add/remove now

Mte90 commented

Ok so I can combine them in the same command.
Thanks