Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class CacheObjectProvider extends CacheInfoRepository
}
final path = await _getPath();
await File(path).parent.create(recursive: true);
await _dropCorruptedDb(path);

db = await openDatabase(path, version: 3,
onCreate: (Database db, int version) async {
await db.execute('''
Expand Down Expand Up @@ -214,4 +216,28 @@ class CacheObjectProvider extends CacheInfoRepository
}
}
}

static Future<void> _dropCorruptedDb(String path) async {
final exists = await File(path).exists();
if (!exists) {
return;
}

Database? pragmaDb;
bool isIntegral = true;

try {
pragmaDb = await openDatabase(path);
final check = await pragmaDb.rawQuery("pragma integrity_check");
isIntegral = check.length == 1 && check[0].values.first == "ok";
} on DatabaseException catch (e) {
isIntegral = false;
} finally {
await pragmaDb?.close();
}

if (!isIntegral) {
await deleteDatabase(path);
}
}
}
Loading