Make a backup of config files before overwriting and make sure the file is fsync'd without error
This commit is contained in:
parent
e12faf5641
commit
9a4bbb771e
|
@ -270,13 +270,26 @@ class Config(object):
|
|||
|
||||
self.__save_timer = None
|
||||
|
||||
# Save the new config and make sure it's written to disk
|
||||
try:
|
||||
log.debug("Saving new config file %s", filename + ".new")
|
||||
json.dump(self.__config, open(filename + ".new", "w"), indent=2)
|
||||
f = open(filename + ".new", "w")
|
||||
json.dump(self.__config, f, indent=2)
|
||||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
f.close()
|
||||
except Exception, e:
|
||||
log.error("Error writing new config file: %s", e)
|
||||
return
|
||||
|
||||
# Make a backup of the old config
|
||||
try:
|
||||
log.debug("Backing up old config file to %s~", filename)
|
||||
shutil.move(filename, filename + "~")
|
||||
except Exception, e:
|
||||
log.error("Error backing up old config..")
|
||||
return
|
||||
|
||||
# The new config file has been written successfully, so let's move it over
|
||||
# the existing one.
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue