atomic write wallet file

This commit is contained in:
ThomasV 2015-04-23 17:12:02 +02:00
parent ab0447d01e
commit 4a28c88946
1 changed files with 2 additions and 1 deletions

View File

@ -136,8 +136,9 @@ class WalletStorage(object):
def write(self): def write(self):
assert not threading.currentThread().isDaemon() assert not threading.currentThread().isDaemon()
s = json.dumps(self.data, indent=4, sort_keys=True) s = json.dumps(self.data, indent=4, sort_keys=True)
with open(self.path,"w") as f: with open(self.path + '.tmp', "w") as f:
f.write(s) f.write(s)
os.rename(self.path + '.tmp', self.path)
if 'ANDROID_DATA' not in os.environ: if 'ANDROID_DATA' not in os.environ:
import stat import stat
os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE) os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE)