From dec32975e2e61245b87bb5a275935c4e30a218e8 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Tue, 14 Sep 2021 10:33:11 +0200 Subject: [PATCH] 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. --- lib/src/database/hive_database.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/database/hive_database.dart b/lib/src/database/hive_database.dart index 9be35b14..d3fc375e 100644 --- a/lib/src/database/hive_database.dart +++ b/lib/src/database/hive_database.dart @@ -249,8 +249,13 @@ class FamedlySdkHiveDatabase extends DatabaseApi { Future clear(int clientId) async { Logs().i('Clear and close hive database...'); await _actionOnAllBoxes((box) async { - await box.deleteAll(box.keys); - await box.close(); + try { + await box.deleteAll(box.keys); + await box.close(); + } catch (e) { + Logs().v('Unable to clear box ${box.name}', e); + await box.deleteFromDisk(); + } }); return; }