2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 09:32:21 +00:00

Fix problem where syncfiles could fail on certan hosts

If the set of oldhosts and newhosts were just so,
targlines or sourcelines could be all
null and cause index errors.
This commit is contained in:
Jarrod Johnson 2021-09-20 08:01:41 -04:00
parent 6acd3c2b7d
commit dd89c48b9a

View File

@ -25,7 +25,7 @@ def partitionhostsline(line):
names = names.split()
return ipaddr, names, comment
class HostMerger:
class HostMerger(object):
def __init__(self):
self.byip = {}
self.byname = {}
@ -75,8 +75,12 @@ class HostMerger:
def write_out(self, targetfile):
while not self.targlines[-1]:
self.targlines = self.targlines[:-1]
if not self.targlines:
break
while not self.sourcelines[-1]:
self.sourcelines = self.sourcelines[:-1]
if not self.sourcelines:
break
with open(targetfile, 'w') as hosts:
for line in self.targlines:
hosts.write(line + '\n')