mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-21 19:48:29 +00:00
Ensure all tables are cleaned up the same before backup import.
This commit is contained in:
@@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.attachments.Attachment
|
||||
import org.thoughtcrime.securesms.attachments.AttachmentId
|
||||
import org.thoughtcrime.securesms.attachments.Cdn
|
||||
import org.thoughtcrime.securesms.attachments.DatabaseAttachment
|
||||
import org.thoughtcrime.securesms.backup.v2.database.clearAllDataForBackup
|
||||
import org.thoughtcrime.securesms.backup.v2.database.clearAllDataForBackupRestore
|
||||
import org.thoughtcrime.securesms.backup.v2.importer.ChatItemArchiveImporter
|
||||
import org.thoughtcrime.securesms.backup.v2.processor.AccountDataArchiveProcessor
|
||||
@@ -386,8 +387,6 @@ object BackupRepository {
|
||||
return ImportResult.Failure
|
||||
}
|
||||
|
||||
// Note: Without a transaction, bad imports could lead to lost data. But because we have a transaction,
|
||||
// writes from other threads are blocked. This is something to think more about.
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.recipients.clearAllDataForBackupRestore()
|
||||
SignalDatabase.distributionLists.clearAllDataForBackupRestore()
|
||||
@@ -398,6 +397,8 @@ object BackupRepository {
|
||||
SignalDatabase.reactions.clearAllDataForBackupRestore()
|
||||
SignalDatabase.inAppPayments.clearAllDataForBackupRestore()
|
||||
SignalDatabase.chatColors.clearAllDataForBackupRestore()
|
||||
SignalDatabase.calls.clearAllDataForBackup()
|
||||
SignalDatabase.callLinks.clearAllDataForBackup()
|
||||
|
||||
// Add back self after clearing data
|
||||
val selfId: RecipientId = SignalDatabase.recipients.getAndPossiblyMerge(selfData.aci, selfData.pni, selfData.e164, pniVerified = true, changeSelf = true)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.thoughtcrime.securesms.backup.v2.database
|
||||
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.deleteAll
|
||||
import org.thoughtcrime.securesms.attachments.Attachment
|
||||
import org.thoughtcrime.securesms.attachments.AttachmentId
|
||||
@@ -12,6 +13,7 @@ import org.thoughtcrime.securesms.database.AttachmentTable
|
||||
|
||||
fun AttachmentTable.clearAllDataForBackupRestore() {
|
||||
writableDatabase.deleteAll(AttachmentTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, AttachmentTable.TABLE_NAME)
|
||||
}
|
||||
|
||||
fun AttachmentTable.restoreWallpaperAttachment(attachment: Attachment): AttachmentId? {
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.thoughtcrime.securesms.backup.v2.database
|
||||
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.deleteAll
|
||||
import org.signal.core.util.select
|
||||
import org.thoughtcrime.securesms.database.CallLinkTable
|
||||
|
||||
@@ -16,3 +18,8 @@ fun CallLinkTable.getCallLinksForBackup(): CallLinkArchiveExporter {
|
||||
|
||||
return CallLinkArchiveExporter(cursor)
|
||||
}
|
||||
|
||||
fun CallLinkTable.clearAllDataForBackup() {
|
||||
writableDatabase.deleteAll(CallLinkTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, CallLinkTable.TABLE_NAME)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.thoughtcrime.securesms.backup.v2.database
|
||||
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.deleteAll
|
||||
import org.signal.core.util.select
|
||||
import org.thoughtcrime.securesms.database.CallTable
|
||||
|
||||
@@ -17,3 +19,8 @@ fun CallTable.getAdhocCallsForBackup(): AdHocCallArchiveExporter {
|
||||
.run()
|
||||
)
|
||||
}
|
||||
|
||||
fun CallTable.clearAllDataForBackup() {
|
||||
writableDatabase.deleteAll(CallTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, CallTable.TABLE_NAME)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
package org.thoughtcrime.securesms.backup.v2.database
|
||||
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.deleteAll
|
||||
import org.thoughtcrime.securesms.database.ChatColorsTable
|
||||
|
||||
fun ChatColorsTable.clearAllDataForBackupRestore() {
|
||||
writableDatabase.deleteAll(ChatColorsTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, ChatColorsTable.TABLE_NAME)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.thoughtcrime.securesms.backup.v2.database
|
||||
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.deleteAll
|
||||
import org.signal.core.util.select
|
||||
import org.signal.core.util.withinTransaction
|
||||
@@ -42,4 +43,6 @@ fun DistributionListTables.getMembersForBackup(id: DistributionListId): List<Rec
|
||||
fun DistributionListTables.clearAllDataForBackupRestore() {
|
||||
writableDatabase.deleteAll(DistributionListTables.ListTable.TABLE_NAME)
|
||||
writableDatabase.deleteAll(DistributionListTables.MembershipTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, DistributionListTables.ListTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, DistributionListTables.MembershipTable.TABLE_NAME)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
package org.thoughtcrime.securesms.backup.v2.database
|
||||
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.deleteAll
|
||||
import org.thoughtcrime.securesms.database.InAppPaymentTable
|
||||
|
||||
fun InAppPaymentTable.clearAllDataForBackupRestore() {
|
||||
writableDatabase.deleteAll(InAppPaymentTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, InAppPaymentTable.TABLE_NAME)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
package org.thoughtcrime.securesms.backup.v2.database
|
||||
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.deleteAll
|
||||
import org.thoughtcrime.securesms.database.ReactionTable
|
||||
|
||||
fun ReactionTable.clearAllDataForBackupRestore() {
|
||||
writableDatabase.deleteAll(ReactionTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, ReactionTable.TABLE_NAME)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
package org.thoughtcrime.securesms.backup.v2.database
|
||||
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.deleteAll
|
||||
import org.thoughtcrime.securesms.database.StickerTable
|
||||
|
||||
fun StickerTable.clearAllDataForBackupRestore() {
|
||||
writableDatabase.deleteAll(StickerTable.TABLE_NAME)
|
||||
SqlUtil.resetAutoIncrementValue(writableDatabase, StickerTable.TABLE_NAME)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user