From 7e3dbb94450bc3f5ace499f4f74a22fb5ae93890 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 12 Nov 2007 23:11:25 +0000
Subject: [PATCH] Fix another breakage in SetEtcHostsEntry

The code assumes all lines have at least two elements which are
whitespace separated - i.e. it does not deal with empty lines or comment
lines with no spaces. This patch fixes this.

Also, the patch replaces the blank between IP and the canonical name
with a tab (restoring previous behaviour).

Reviewed-by: imsnah
---
 lib/utils.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/utils.py b/lib/utils.py
index 53fa6f26c..73d1bbb8e 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -765,11 +765,11 @@ def SetEtcHostsEntry(file_name, ip, hostname, aliases):
         written = False
         for line in f:
           fields = line.split()
-          if not fields[0].startswith('#') and ip == fields[0]:
+          if fields and not fields[0].startswith('#') and ip == fields[0]:
             continue
           out.write(line)
 
-        out.write("%s %s" % (ip, hostname))
+        out.write("%s\t%s" % (ip, hostname))
         if aliases:
           out.write(" %s" % ' '.join(aliases))
         out.write('\n')
-- 
GitLab