Ensure that we clear incrementalMac's that will be invalidated during archive.

This commit is contained in:
Greyson Parrelli
2025-08-22 09:35:18 -04:00
committed by Michelle Tang
parent bed718347c
commit a234896438
2 changed files with 26 additions and 0 deletions

View File

@@ -683,6 +683,29 @@ class AttachmentTable(
return count
}
/**
* Clears incrementalMac's for any attachments that still need to be uploaded.
* This is important because when we upload an attachment to the archive CDN, we'll be re-encrypting it, and so the incrementalMac will end up changing.
* So we want to be sure that we don't write a potentially-invalid incrementalMac in the meantime.
*/
fun clearIncrementalMacsForAttachmentsThatNeedArchiveUpload(): Int {
return writableDatabase
.update(TABLE_NAME)
.values(
REMOTE_INCREMENTAL_DIGEST to null,
REMOTE_INCREMENTAL_DIGEST_CHUNK_SIZE to 0
)
.where(
"""
$ARCHIVE_TRANSFER_STATE = ${ArchiveTransferState.NONE.value} AND
$DATA_FILE NOT NULL AND
$TRANSFER_STATE = $TRANSFER_PROGRESS_DONE AND
$REMOTE_INCREMENTAL_DIGEST NOT NULL
"""
)
.run()
}
/**
* Similar to [getAttachmentsThatNeedArchiveUpload], but returns if the list would be non-null in a more efficient way.
*/

View File

@@ -182,6 +182,9 @@ class BackupMessagesJob private constructor(
SignalDatabase.attachments.createRemoteKeyForAttachmentsThatNeedArchiveUpload().takeIf { it > 0 }?.let { count -> Log.w(TAG, "Needed to create $count remote keys.") }
stopwatch.split("keygen")
SignalDatabase.attachments.clearIncrementalMacsForAttachmentsThatNeedArchiveUpload().takeIf { it > 0 }?.let { count -> Log.w(TAG, "Needed to clear $count incrementalMacs.") }
stopwatch.split("clear-incmac")
if (isCanceled) {
return Result.failure()
}