mirror of
https://github.com/StevenBlack/hosts.git
synced 2024-07-12 07:12:52 +02:00
Modified the removeOldHostsFile() function to keep backups of the old hosts file.
This commit is contained in:
parent
8930205670
commit
df45003106
@ -15,10 +15,12 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import time
|
||||||
import glob
|
import glob
|
||||||
import argparse
|
import argparse
|
||||||
# zip files are not used actually, support deleted
|
# zip files are not used actually, support deleted
|
||||||
@ -353,6 +355,8 @@ def moveHostsFileIntoPlace(finalFile):
|
|||||||
def removeOldHostsFile(): # hotfix since merging with an already existing hosts file leads to artefacts and duplicates
|
def removeOldHostsFile(): # hotfix since merging with an already existing hosts file leads to artefacts and duplicates
|
||||||
oldFilePath = os.path.join(BASEDIR_PATH, 'hosts')
|
oldFilePath = os.path.join(BASEDIR_PATH, 'hosts')
|
||||||
open(oldFilePath, 'a').close() # create if already removed, so remove wont raise an error
|
open(oldFilePath, 'a').close() # create if already removed, so remove wont raise an error
|
||||||
|
backupFilePath = os.path.join(BASEDIR_PATH, 'hosts-{0}'.format(time.strftime("%c")))
|
||||||
|
shutil.copyfile(oldFilePath, backupFilePath) # make a backup copy, marking the date in which the list was updated
|
||||||
os.remove(oldFilePath)
|
os.remove(oldFilePath)
|
||||||
open(oldFilePath, 'a').close() # create new empty hostsfile
|
open(oldFilePath, 'a').close() # create new empty hostsfile
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user