Backup keys.dat before writing #752

Merged
Atheros1 merged 5 commits from master into master 2014-12-26 03:09:16 +01:00
2 changed files with 10 additions and 4 deletions
Showing only changes of commit 9b6bc26144 - Show all commits

View File

@ -2426,7 +2426,8 @@ class MyForm(QtGui.QMainWindow):
if shared.appdata != '' and self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we are NOT using portable mode now but the user selected that we should...
# Write the keys.dat file to disk in the new location
sqlStoredProcedure('movemessagstoprog')
shared.writeKeysFile()
with open('keys.dat', 'wb') as configfile:
shared.config.write(configfile)
# Write the knownnodes.dat file to disk in the new location
shared.knownNodesLock.acquire()
output = open('knownnodes.dat', 'wb')

View File

@ -850,12 +850,17 @@ def writeKeysFile():
fileName = shared.appdata + 'keys.dat'
fileNameBak = fileName + "." + datetime.datetime.now().strftime("%Y%j%H%M%S%f") + '.bak'
# create a backup copy to prevent the accidental loss due to the disk write failure
shutil.copyfile(fileName, fileNameBak)
try:
shutil.copyfile(fileName, fileNameBak)
# The backup succeeded. This can fail if the file didn't exist before.
existingFileNameExisted = True
except:
existingFileNameExisted = False
# write the file
with open(fileName, 'wb') as configfile:
shared.config.write(configfile)
# delete a backup
os.remove(fileNameBak)
if existingFileNameExisted:
os.remove(fileNameBak)
helper_startup.loadConfig()
from debug import logger