From d3c91eea3bb960bcc85a1875d95fad3465265177 Mon Sep 17 00:00:00 2001 From: Yuri Date: Sun, 14 Sep 2014 23:53:21 -0700 Subject: [PATCH] Added backup copy creation during keys.dat write to prevent an accidental file loss due to the disk failure. --- src/shared.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shared.py b/src/shared.py index 14a82f41..32e4b118 100644 --- a/src/shared.py +++ b/src/shared.py @@ -20,6 +20,7 @@ import sys import stat import threading import time +import shutil # used for moving the data folder and copying keys.dat from os import path, environ from struct import Struct @@ -799,8 +800,14 @@ def openKeysFile(): os.startfile(shared.appdata + 'keys.dat') def writeKeysFile(): - with open(shared.appdata + 'keys.dat', 'wb') as configfile: + fileName = shared.appdata + 'keys.dat' + # create a backup copy to prevent the accidental loss due to the disk write failure + shutil.copyfile(fileName, fileName + '.bak') + # write the file + with open(fileName, 'wb') as configfile: shared.config.write(configfile) + # delete a backup + os.remove(fileName + '.bak') helper_startup.loadConfig() from debug import logger