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