refactor: Delete database file on failed app start

pull/1113/head^2
krille-chan 1 year ago
parent 3b76219f68
commit f7096d5dee
No known key found for this signature in database

@ -35,6 +35,12 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
), ),
); );
// Delete database file:
if (database == null && !kIsWeb) {
final dbFile = File(await _getDatabasePath(client.clientName));
if (await dbFile.exists()) await dbFile.delete();
}
try { try {
// Send error notification: // Send error notification:
final l10n = lookupL10n(PlatformDispatcher.instance.locale); final l10n = lookupL10n(PlatformDispatcher.instance.locale);
@ -61,9 +67,6 @@ Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
final cipher = await getDatabaseCipher(); final cipher = await getDatabaseCipher();
final databaseDirectory = PlatformInfos.isIOS || PlatformInfos.isMacOS
? await getLibraryDirectory()
: await getApplicationSupportDirectory();
Directory? fileStorageLocation; Directory? fileStorageLocation;
try { try {
fileStorageLocation = await getTemporaryDirectory(); fileStorageLocation = await getTemporaryDirectory();
@ -73,7 +76,7 @@ Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
); );
} }
final path = join(databaseDirectory.path, '${client.clientName}.sqlite'); final path = await _getDatabasePath(client.clientName);
// fix dlopen for old Android // fix dlopen for old Android
await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions(); await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions();
@ -118,6 +121,14 @@ Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
); );
} }
Future<String> _getDatabasePath(String clientName) async {
final databaseDirectory = PlatformInfos.isIOS || PlatformInfos.isMacOS
? await getLibraryDirectory()
: await getApplicationSupportDirectory();
return join(databaseDirectory.path, '$clientName.sqlite');
}
Future<void> _migrateLegacyLocation( Future<void> _migrateLegacyLocation(
String sqlFilePath, String sqlFilePath,
String clientName, String clientName,

Loading…
Cancel
Save