From 9b6bc26144395e05bdc3ae06098a92260f2b48b8 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Thu, 25 Dec 2014 21:06:10 -0500 Subject: [PATCH] fix bug in #715 --- src/bitmessageqt/__init__.py | 3 ++- src/shared.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 95eb7d12..d3bf8dae 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -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') diff --git a/src/shared.py b/src/shared.py index df37c1b4..8f4be2ff 100644 --- a/src/shared.py +++ b/src/shared.py @@ -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