Merge pull request #45 from bdcribbs/fix/44

Handle destroyed machines in update_file.  Fixes #44
This commit is contained in:
Bryan Cribbs 2013-11-15 16:13:38 -08:00
commit 6c5f3ed972
1 changed files with 9 additions and 2 deletions

View File

@ -54,6 +54,7 @@ module VagrantPlugins
def update_file(file)
# build array of host file entries from Vagrant configuration
entries = []
destroyed_entries = []
ids = []
get_machines.each do |name, p|
if @provider == p
@ -62,15 +63,21 @@ module VagrantPlugins
id = machine.id
ip = get_ip_address(machine)
aliases = machine.config.hostmanager.aliases.join(' ').chomp
if id.nil?
destroyed_entries << "#{ip}\t#{host} #{aliases}"
else
entries << "#{ip}\t#{host} #{aliases}\t# VAGRANT ID: #{id}\n"
ids << id unless ids.include?(id)
end
end
end
tmp_file = Tempfile.open('hostmanager', @global_env.tmp_path, 'a')
begin
# copy each line not managed by Vagrant
File.open(file).each_line do |line|
# Eliminate lines for machines that have been destroyed
next if destroyed_entries.any? { |entry| line =~ /^#{entry}\t# VAGRANT ID: .*/ }
tmp_file << line unless ids.any? { |id| line =~ /# VAGRANT ID: #{id}/ }
end