fix(db): remove db temp files as well

This commit is contained in:
Evan Morikawa 2015-09-04 14:34:09 -07:00
parent 7126d708ca
commit f8cb9a81eb
2 changed files with 9 additions and 3 deletions

View file

@ -131,6 +131,7 @@ class Application
# exit and then delete the file. It's hard to tell when this happens, so we just # exit and then delete the file. It's hard to tell when this happens, so we just
# retry the deletion a few times. # retry the deletion a few times.
deleteFileWithRetry: (filePath, callback, retries = 5) -> deleteFileWithRetry: (filePath, callback, retries = 5) ->
callback ?= ->
callbackWithRetry = (err) => callbackWithRetry = (err) =>
if err and err.message.indexOf('no such file') is -1 if err and err.message.indexOf('no such file') is -1
console.log("File Error: #{err.message} - retrying in 150msec") console.log("File Error: #{err.message} - retrying in 150msec")
@ -163,13 +164,18 @@ class Application
_logout: => _logout: =>
@setDatabasePhase('close') @setDatabasePhase('close')
@windowManager.closeAllWindows() @windowManager.closeAllWindows()
@deleteFileWithRetry path.join(configDirPath,'edgehill.db'), => @_deleteDatabase =>
@config.set('tokens', null) @config.set('tokens', null)
@config.set('nylas', null) @config.set('nylas', null)
@config.set('edgehill', null) @config.set('edgehill', null)
@setDatabasePhase('setup') @setDatabasePhase('setup')
@openWindowsForTokenState() @openWindowsForTokenState()
_deleteDatabase: (callback) ->
@deleteFileWithRetry path.join(configDirPath,'edgehill.db'), callback
@deleteFileWithRetry path.join(configDirPath,'edgehill.db-wal')
@deleteFileWithRetry path.join(configDirPath,'edgehill.db-shm')
_loginSuccessful: => _loginSuccessful: =>
@openWindowsForTokenState() @openWindowsForTokenState()
@windowManager.mainWindow().waitForLoad => @windowManager.mainWindow().waitForLoad =>
@ -203,7 +209,7 @@ class Application
detail: 'Welcome back to Nylas! We need to rebuild your mailbox to support new features. Please wait a few moments while we re-sync your mail.' detail: 'Welcome back to Nylas! We need to rebuild your mailbox to support new features. Please wait a few moments while we re-sync your mail.'
buttons: ['OK'] buttons: ['OK']
@deleteFileWithRetry path.join(configDirPath,'edgehill.db'), => @_deleteDatabase =>
@setDatabasePhase('setup') @setDatabasePhase('setup')
@openWindowsForTokenState() @openWindowsForTokenState()

View file

@ -17,7 +17,7 @@ PriorityUICoordinator = require '../../priority-ui-coordinator'
serializeRegisteredObjects, serializeRegisteredObjects,
deserializeRegisteredObjects} = require '../models/utils' deserializeRegisteredObjects} = require '../models/utils'
DatabaseVersion = 13 DatabaseVersion = 14
DatabasePhase = DatabasePhase =
Setup: 'setup' Setup: 'setup'