Merge pull request #45 from bdcribbs/fix/44
Handle destroyed machines in update_file. Fixes #44
This commit is contained in:
commit
6c5f3ed972
|
@ -54,6 +54,7 @@ module VagrantPlugins
|
||||||
def update_file(file)
|
def update_file(file)
|
||||||
# build array of host file entries from Vagrant configuration
|
# build array of host file entries from Vagrant configuration
|
||||||
entries = []
|
entries = []
|
||||||
|
destroyed_entries = []
|
||||||
ids = []
|
ids = []
|
||||||
get_machines.each do |name, p|
|
get_machines.each do |name, p|
|
||||||
if @provider == p
|
if @provider == p
|
||||||
|
@ -62,15 +63,21 @@ module VagrantPlugins
|
||||||
id = machine.id
|
id = machine.id
|
||||||
ip = get_ip_address(machine)
|
ip = get_ip_address(machine)
|
||||||
aliases = machine.config.hostmanager.aliases.join(' ').chomp
|
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"
|
entries << "#{ip}\t#{host} #{aliases}\t# VAGRANT ID: #{id}\n"
|
||||||
ids << id unless ids.include?(id)
|
ids << id unless ids.include?(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
tmp_file = Tempfile.open('hostmanager', @global_env.tmp_path, 'a')
|
tmp_file = Tempfile.open('hostmanager', @global_env.tmp_path, 'a')
|
||||||
begin
|
begin
|
||||||
# copy each line not managed by Vagrant
|
# copy each line not managed by Vagrant
|
||||||
File.open(file).each_line do |line|
|
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}/ }
|
tmp_file << line unless ids.any? { |id| line =~ /# VAGRANT ID: #{id}/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue