Skip to content

Commit 36418be

Browse files
Ensure SqlCipherDeletingErrorHandler runs delete.
1 parent 07bd8b2 commit 36418be

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

app/src/main/java/org/thoughtcrime/securesms/database/SqlCipherDeletingErrorHandler.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@ public SqlCipherDeletingErrorHandler(@NonNull String databaseName) {
2828

2929
@Override
3030
public void onCorruption(SQLiteDatabase db, String message) {
31-
Log.e(TAG, "Database '" + databaseName + "' corrupted! Message: " + message + ". Going to try to run some diagnostics.");
32-
33-
Log.w(TAG, " ===== PRAGMA integrity_check =====");
34-
try (Cursor cursor = db.rawQuery("PRAGMA integrity_check", null)) {
35-
while (cursor.moveToNext()) {
36-
Log.w(TAG, CursorUtil.readRowAsString(cursor));
31+
try {
32+
Log.e(TAG, "Database '" + databaseName + "' corrupted! Message: " + message + ". Going to try to run some diagnostics.");
33+
34+
Log.w(TAG, " ===== PRAGMA integrity_check =====");
35+
try (Cursor cursor = db.rawQuery("PRAGMA integrity_check", null)) {
36+
while (cursor.moveToNext()) {
37+
Log.w(TAG, CursorUtil.readRowAsString(cursor));
38+
}
39+
} catch (Throwable t) {
40+
Log.e(TAG, "Failed to do integrity_check!", t);
3741
}
38-
} catch (Throwable t) {
39-
Log.e(TAG, "Failed to do integrity_check!", t);
40-
}
4142

42-
Log.w(TAG, "===== PRAGMA cipher_integrity_check =====");
43-
try (Cursor cursor = db.rawQuery("PRAGMA cipher_integrity_check", null)) {
44-
while (cursor.moveToNext()) {
45-
Log.w(TAG, CursorUtil.readRowAsString(cursor));
43+
Log.w(TAG, "===== PRAGMA cipher_integrity_check =====");
44+
try (Cursor cursor = db.rawQuery("PRAGMA cipher_integrity_check", null)) {
45+
while (cursor.moveToNext()) {
46+
Log.w(TAG, CursorUtil.readRowAsString(cursor));
47+
}
48+
} catch (Throwable t) {
49+
Log.e(TAG, "Failed to do cipher_integrity_check!", t);
4650
}
47-
} catch (Throwable t) {
48-
Log.e(TAG, "Failed to do cipher_integrity_check!", t);
51+
} finally {
52+
Log.w(TAG, "Deleting database " + databaseName);
53+
ApplicationDependencies.getApplication().deleteDatabase(databaseName);
4954
}
50-
51-
ApplicationDependencies.getApplication().deleteDatabase(databaseName);
5255
}
5356
}

0 commit comments

Comments
 (0)