Rev3739, Fix atomicWrite of non existent file

This commit is contained in:
shortcutme 2018-12-13 21:17:36 +01:00
parent ed74403850
commit edc1a71d0d
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
2 changed files with 4 additions and 3 deletions

View file

@ -13,7 +13,7 @@ class Config(object):
def __init__(self, argv):
self.version = "0.6.4"
self.rev = 3738
self.rev = 3739
self.argv = argv
self.action = None
self.pending_changes = {}

View file

@ -20,9 +20,10 @@ def atomicWrite(dest, content, mode="w"):
os.fsync(f.fileno())
if os.path.isfile(dest + "-tmpold"): # Previous incomplete write
os.rename(dest + "-tmpold", dest + "-tmpold-%s" % time.time())
os.rename(dest, dest + "-tmpold")
if os.path.isfile(dest): # Rename old file to -tmpold
os.rename(dest, dest + "-tmpold")
os.rename(dest + "-tmpnew", dest)
os.unlink(dest + "-tmpold")
os.unlink(dest + "-tmpold") # Remove old file
return True
except Exception, err:
from Debug import Debug