From cb9832a399e4e5d40b01de9aa413703216ef6bb2 Mon Sep 17 00:00:00 2001 From: "S. Brent Faulkner" Date: Tue, 3 Sep 2013 15:32:54 -0400 Subject: [PATCH] only remove lines for the current vagrantfile --- lib/vagrant-hostmanager/hosts_file.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-hostmanager/hosts_file.rb b/lib/vagrant-hostmanager/hosts_file.rb index 29466ea..bc3c753 100644 --- a/lib/vagrant-hostmanager/hosts_file.rb +++ b/lib/vagrant-hostmanager/hosts_file.rb @@ -44,6 +44,7 @@ module VagrantPlugins def update_file(file) # build array of host file entries from Vagrant configuration entries = [] + ids = [] get_machines.each do |name, p| if @provider == p machine = @global_env.machine(name, p) @@ -52,6 +53,7 @@ module VagrantPlugins ip = get_ip_address(machine) aliases = machine.config.hostmanager.aliases.join(' ').chomp entries << "#{ip}\t#{host} #{aliases}\t# VAGRANT ID: #{id}\n" + ids << id unless ids.include?(id) end end @@ -59,7 +61,7 @@ module VagrantPlugins begin # copy each line not managed by Vagrant File.open(file).each_line do |line| - tmp_file << line unless line =~ /# VAGRANT ID:/ + tmp_file << line unless ids.any? { |id| line =~ /# VAGRANT ID: #{id}/ } end # write a line for each Vagrant-managed entry