fix: Delete database correctly after corruption
This commit is contained in:
parent
89044f215f
commit
9e416eefa1
1 changed files with 13 additions and 16 deletions
|
|
@ -8,7 +8,6 @@ import 'package:path_provider/path_provider.dart';
|
|||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/utils/client_manager.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
|
|
@ -25,6 +24,18 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(String clientName) async {
|
|||
return database;
|
||||
} catch (e, s) {
|
||||
Logs().wtf('Unable to construct database!', e, s);
|
||||
|
||||
try {
|
||||
// Send error notification:
|
||||
final l10n = await lookupL10n(PlatformDispatcher.instance.locale);
|
||||
ClientManager.sendInitNotification(
|
||||
l10n.initAppError,
|
||||
e.toString(),
|
||||
);
|
||||
} catch (e, s) {
|
||||
Logs().e('Unable to send error notification', e, s);
|
||||
}
|
||||
|
||||
// Try to delete database so that it can created again on next init:
|
||||
database?.delete().catchError(
|
||||
(e, s) => Logs().wtf(
|
||||
|
|
@ -35,25 +46,11 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(String clientName) async {
|
|||
);
|
||||
|
||||
// Delete database file:
|
||||
if (database == null && !kIsWeb) {
|
||||
if (!kIsWeb) {
|
||||
final dbFile = File(await _getDatabasePath(clientName));
|
||||
if (await dbFile.exists()) await dbFile.delete();
|
||||
}
|
||||
|
||||
try {
|
||||
// Send error notification:
|
||||
final l10n = await lookupL10n(PlatformDispatcher.instance.locale);
|
||||
ClientManager.sendInitNotification(
|
||||
l10n.initAppError,
|
||||
l10n.databaseBuildErrorBody(
|
||||
AppConfig.newIssueUrl.toString(),
|
||||
e.toString(),
|
||||
),
|
||||
);
|
||||
} catch (e, s) {
|
||||
Logs().e('Unable to send error notification', e, s);
|
||||
}
|
||||
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue