chore: Update SDK and remove boxes on corruption

This commit is contained in:
Krille Fear 2021-11-21 12:01:53 +01:00
commit 335fe36130
2 changed files with 14 additions and 3 deletions

View file

@ -12,6 +12,9 @@ import 'package:hive_flutter/hive_flutter.dart';
import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart';
import '../client_manager.dart';
import '../famedlysdk_store.dart';
class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
FlutterFluffyBoxDatabase(
String name,
@ -60,7 +63,15 @@ class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
await _findDatabasePath(client),
key: hiverCipher,
);
await db.open();
try {
await db.open();
} catch (_) {
Logs().w('Unable to open FluffyBox. Delete database and storage key...');
await Store().deleteItem(ClientManager.clientNamespace);
const FlutterSecureStorage().delete(key: _cipherStorageKey);
await db.clear();
rethrow;
}
Logs().d('FluffyBox is ready');
return db;
}