From 5f2bb91173ffdf8aa8efa7a119801a32d7487f93 Mon Sep 17 00:00:00 2001 From: Hannes Domschke Date: Sun, 15 Nov 2015 22:38:07 +0100 Subject: [PATCH 1/2] hotfix for duplicates and artefacts --- updateHostsFile.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/updateHostsFile.py b/updateHostsFile.py index ea5a5130f..8047d734e 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -90,6 +90,7 @@ exclusionRegexs = [] numberOfRules = 0 def main(): + removeOldHostsFile() promptForUpdate() promptForExclusions() mergeFile = createInitialFile() @@ -313,6 +314,12 @@ def moveHostsFileIntoPlace(finalFile): elif (os.name == 'nt'): print ('Automatically moving the hosts file in place is not yet supported.') print ('Please move the generated file to %SystemRoot%\system32\drivers\etc\hosts') + +def removeOldHostsFile(): # hotfix since merging with an already existing hosts file leads to artefacts and duplicates + oldFilePath=os.path.join(BASEDIR_PATH,'hosts') + open(oldFilePath, 'a').close() # create if already removed, so remove wont raise an error + os.remove(oldFilePath); + open(oldFilePath, 'a').close() # create new empty hostsfile # End File Logic From 2b18fa1e1a2b53cf1f6334cefe5e4fb7ea59e263 Mon Sep 17 00:00:00 2001 From: Hannes Domschke Date: Sun, 15 Nov 2015 23:23:06 +0100 Subject: [PATCH 2/2] better delete after updating so we dont end up with an empty hosts file if update goes wrong and causes a crash --- updateHostsFile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index 8047d734e..9f3b64286 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -90,10 +90,10 @@ exclusionRegexs = [] numberOfRules = 0 def main(): - removeOldHostsFile() promptForUpdate() promptForExclusions() mergeFile = createInitialFile() + removeOldHostsFile() finalFile = removeDupsAndExcl(mergeFile) finalizeFile(finalFile) updateReadme(numberOfRules)