Fix issue where FTS recovery path didn't work during migrations.

There was a recursive getDatabase() call because it was happening during
a migration. Solution was to re-use the DB instance we already had.
This commit is contained in:
Greyson Parrelli
2023-06-23 09:55:24 -04:00
committed by Nicholas Tinsley
parent 1a1923c6c0
commit 2dd0221680
2 changed files with 6 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.database.Cursor
import android.text.TextUtils
import net.zetetic.database.sqlcipher.SQLiteDatabase
import org.intellij.lang.annotations.Language
import org.signal.core.util.SqlUtil
import org.signal.core.util.ThreadUtil
@@ -231,7 +232,8 @@ class SearchTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
/**
* Drops all tables and recreates them.
*/
fun fullyResetTables() {
@JvmOverloads
fun fullyResetTables(db: SQLiteDatabase = writableDatabase.sqlCipherDatabase) {
Log.w(TAG, "[fullyResetTables] Dropping tables and triggers...")
writableDatabase.execSQL("DROP TABLE IF EXISTS $FTS_TABLE_NAME")
writableDatabase.execSQL("DROP TABLE IF EXISTS ${FTS_TABLE_NAME}_config")

View File

@@ -35,7 +35,7 @@ class SqlCipherErrorHandler(private val databaseName: String) : DatabaseErrorHan
endCount++
}
attemptToClearFullTextSearchIndex()
attemptToClearFullTextSearchIndex(db)
throw DatabaseCorruptedError_BothChecksPass(lines)
} else if (!result.pragma1Passes && result.pragma2Passes) {
throw DatabaseCorruptedError_NormalCheckFailsCipherCheckPasses(lines)
@@ -144,9 +144,9 @@ class SqlCipherErrorHandler(private val databaseName: String) : DatabaseErrorHan
}
}
private fun attemptToClearFullTextSearchIndex() {
private fun attemptToClearFullTextSearchIndex(db: SQLiteDatabase) {
try {
SignalDatabase.messageSearch.fullyResetTables()
SignalDatabase.messageSearch.fullyResetTables(db)
} catch (e: Throwable) {
Log.w(TAG, "Failed to clear full text search index.", e)
}