Merge pull request #909 from Chessing234/fix/panic-wipe-destroy-db-on-failure

fix: destroy conversation database files when panic wipe throws
This commit is contained in:
callebtc 2026-08-25 14:37:58 +02:00 committed by GitHub
commit 33c1ebfc60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -317,6 +317,7 @@ class ConversationRepository internal constructor(
true
} catch (error: Exception) {
Log.e(TAG, "Unable to synchronously clear private conversations", error)
database.destroyStorage()
_storeState.value = ConversationStoreState.Error(
error.message ?: "Unable to erase conversations"
)
@ -1097,6 +1098,22 @@ internal class ConversationDatabase(
writableDatabase.rawQuery("PRAGMA incremental_vacuum", null).use { }
}
/**
* Last-resort panic cleanup when [clearAll] throws: drop the encrypted database
* files so a later reload cannot resurrect erased conversations (#699).
*/
fun destroyStorage() {
try {
clearAll()
} catch (error: Exception) {
Log.e(TAG, "clearAll failed during destroyStorage; deleting database files", error)
}
try {
close()
} catch (_: Exception) { }
applicationContext.deleteDatabase(databaseName)
}
fun pruneToRetentionLimits(): Set<String> {
val db = writableDatabase
val orphanedMediaPaths = linkedSetOf<String>()

View File

@ -433,6 +433,22 @@ class ConversationDatabaseTest {
}
}
@Test
fun `destroy storage deletes database files so history cannot reload`() {
database.upsertMessage(
"contact_alice",
setOf("contact_alice"),
"alice",
message("survives-failure", "alice", 1L),
true
)
assertTrue(context.databaseList().contains(databaseName))
database.destroyStorage()
assertFalse(context.databaseList().contains(databaseName))
}
@Test
fun `version one plaintext database migrates without losing history`() {
database.close()