fix: Clearing corrupted boxes

If a box is corrupted the clear function fails on it. Then
we should delete the box from the disk.
Currently we use the Hive.deletefromDisk() method which does not
work because it deletes only open boxes, but the box is obviously not open in
this case.
This commit is contained in:
Krille Fear 2021-09-14 10:33:11 +02:00
parent 00cc439122
commit dec32975e2
1 changed files with 7 additions and 2 deletions

View File

@ -249,8 +249,13 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
Future<void> clear(int clientId) async { Future<void> clear(int clientId) async {
Logs().i('Clear and close hive database...'); Logs().i('Clear and close hive database...');
await _actionOnAllBoxes((box) async { await _actionOnAllBoxes((box) async {
try {
await box.deleteAll(box.keys); await box.deleteAll(box.keys);
await box.close(); await box.close();
} catch (e) {
Logs().v('Unable to clear box ${box.name}', e);
await box.deleteFromDisk();
}
}); });
return; return;
} }