Remove archive_transfer_file column.

This commit is contained in:
Greyson Parrelli
2025-06-24 09:28:44 -04:00
committed by Cody Henthorne
parent 03dc014c08
commit b1063f69f9
5 changed files with 27 additions and 44 deletions

View File

@@ -216,7 +216,6 @@ class AttachmentTable(
DATA_HASH_START, DATA_HASH_START,
DATA_HASH_END, DATA_HASH_END,
ARCHIVE_CDN, ARCHIVE_CDN,
ARCHIVE_TRANSFER_FILE,
THUMBNAIL_FILE, THUMBNAIL_FILE,
THUMBNAIL_RESTORE_STATE, THUMBNAIL_RESTORE_STATE,
ARCHIVE_TRANSFER_STATE, ARCHIVE_TRANSFER_STATE,
@@ -260,7 +259,6 @@ class AttachmentTable(
$DATA_HASH_START TEXT DEFAULT NULL, $DATA_HASH_START TEXT DEFAULT NULL,
$DATA_HASH_END TEXT DEFAULT NULL, $DATA_HASH_END TEXT DEFAULT NULL,
$ARCHIVE_CDN INTEGER DEFAULT NULL, $ARCHIVE_CDN INTEGER DEFAULT NULL,
$ARCHIVE_TRANSFER_FILE TEXT DEFAULT NULL,
$ARCHIVE_TRANSFER_STATE INTEGER DEFAULT ${ArchiveTransferState.NONE.value}, $ARCHIVE_TRANSFER_STATE INTEGER DEFAULT ${ArchiveTransferState.NONE.value},
$THUMBNAIL_FILE TEXT DEFAULT NULL, $THUMBNAIL_FILE TEXT DEFAULT NULL,
$THUMBNAIL_RANDOM BLOB DEFAULT NULL, $THUMBNAIL_RANDOM BLOB DEFAULT NULL,
@@ -1203,7 +1201,6 @@ class AttachmentTable(
values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE) values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE)
values.put(TRANSFER_FILE, null as String?) values.put(TRANSFER_FILE, null as String?)
values.put(TRANSFORM_PROPERTIES, TransformProperties.forSkipTransform().serialize()) values.put(TRANSFORM_PROPERTIES, TransformProperties.forSkipTransform().serialize())
values.put(ARCHIVE_TRANSFER_FILE, null as String?)
values.put(REMOTE_LOCATION, existingPlaceholder.remoteLocation) values.put(REMOTE_LOCATION, existingPlaceholder.remoteLocation)
values.put(CDN_NUMBER, existingPlaceholder.cdn.serialize()) values.put(CDN_NUMBER, existingPlaceholder.cdn.serialize())
values.put(REMOTE_KEY, existingPlaceholder.remoteKey!!) values.put(REMOTE_KEY, existingPlaceholder.remoteKey!!)
@@ -1624,24 +1621,6 @@ class AttachmentTable(
return transferFile return transferFile
} }
@Throws(IOException::class)
fun getOrCreateArchiveTransferFile(attachmentId: AttachmentId): File {
val existing = getArchiveTransferFile(writableDatabase, attachmentId)
if (existing != null) {
return existing
}
val transferFile = newTransferFile()
writableDatabase
.update(TABLE_NAME)
.values(ARCHIVE_TRANSFER_FILE to transferFile.absolutePath)
.where("$ID = ?", attachmentId.id)
.run()
return transferFile
}
fun createArchiveThumbnailTransferFile(): File { fun createArchiveThumbnailTransferFile(): File {
return newTransferFile() return newTransferFile()
} }
@@ -2455,18 +2434,6 @@ class AttachmentTable(
} }
} }
private fun getArchiveTransferFile(db: SQLiteDatabase, attachmentId: AttachmentId): File? {
return db
.select(ARCHIVE_TRANSFER_FILE)
.from(TABLE_NAME)
.where("$ID = ?", attachmentId.id)
.limit(1)
.run()
.readToSingleObject { cursor ->
cursor.requireString(ARCHIVE_TRANSFER_FILE)?.let { File(it) }
}
}
private fun getAttachment(cursor: Cursor): DatabaseAttachment { private fun getAttachment(cursor: Cursor): DatabaseAttachment {
val contentType = cursor.requireString(CONTENT_TYPE) val contentType = cursor.requireString(CONTENT_TYPE)

View File

@@ -135,6 +135,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V277_AddNotificatio
import org.thoughtcrime.securesms.database.helpers.migration.V278_BackupSnapshotTableVersions import org.thoughtcrime.securesms.database.helpers.migration.V278_BackupSnapshotTableVersions
import org.thoughtcrime.securesms.database.helpers.migration.V279_AddNotificationProfileForeignKey import org.thoughtcrime.securesms.database.helpers.migration.V279_AddNotificationProfileForeignKey
import org.thoughtcrime.securesms.database.helpers.migration.V280_RemoveAttachmentIv import org.thoughtcrime.securesms.database.helpers.migration.V280_RemoveAttachmentIv
import org.thoughtcrime.securesms.database.helpers.migration.V281_RemoveArchiveTransferFile
import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase
/** /**
@@ -275,10 +276,11 @@ object SignalDatabaseMigrations {
277 to V277_AddNotificationProfileStorageSync, 277 to V277_AddNotificationProfileStorageSync,
278 to V278_BackupSnapshotTableVersions, 278 to V278_BackupSnapshotTableVersions,
279 to V279_AddNotificationProfileForeignKey, 279 to V279_AddNotificationProfileForeignKey,
280 to V280_RemoveAttachmentIv 280 to V280_RemoveAttachmentIv,
281 to V281_RemoveArchiveTransferFile
) )
const val DATABASE_VERSION = 280 const val DATABASE_VERSION = 281
@JvmStatic @JvmStatic
fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) { fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) {

View File

@@ -0,0 +1,19 @@
/*
* Copyright 2025 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import org.thoughtcrime.securesms.database.SQLiteDatabase
/**
* We used to decrypt archive files in two distinct steps, and therefore needed a secondary transfer file.
* Now, we're able to do all of the decrypt in one stream, so we no longer need the intermediary transfer file.
*/
object V281_RemoveArchiveTransferFile : SignalDatabaseMigration {
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
db.execSQL("ALTER TABLE attachment DROP COLUMN archive_transfer_file")
}
}

View File

@@ -230,7 +230,6 @@ class RestoreAttachmentJob private constructor(
) { ) {
val maxReceiveSize: Long = RemoteConfig.maxAttachmentReceiveSizeBytes val maxReceiveSize: Long = RemoteConfig.maxAttachmentReceiveSizeBytes
val attachmentFile: File = SignalDatabase.attachments.getOrCreateTransferFile(attachmentId) val attachmentFile: File = SignalDatabase.attachments.getOrCreateTransferFile(attachmentId)
var archiveFile: File? = null
var useArchiveCdn = false var useArchiveCdn = false
if (attachment.remoteDigest == null && attachment.dataHash == null) { if (attachment.remoteDigest == null && attachment.dataHash == null) {
@@ -267,9 +266,6 @@ class RestoreAttachmentJob private constructor(
} }
val decryptingStream = if (useArchiveCdn) { val decryptingStream = if (useArchiveCdn) {
// TODO next PR: remove archive transfer file and just use the regular attachment file
archiveFile = attachmentFile
// archiveFile = SignalDatabase.attachments.getOrCreateArchiveTransferFile(attachmentId)
val cdnCredentials = BackupRepository.getCdnReadCredentials(BackupRepository.CredentialType.MEDIA, attachment.archiveCdn ?: RemoteConfig.backupFallbackArchiveCdn).successOrThrow().headers val cdnCredentials = BackupRepository.getCdnReadCredentials(BackupRepository.CredentialType.MEDIA, attachment.archiveCdn ?: RemoteConfig.backupFallbackArchiveCdn).successOrThrow().headers
messageReceiver messageReceiver
@@ -277,7 +273,7 @@ class RestoreAttachmentJob private constructor(
SignalStore.backup.mediaRootBackupKey.deriveMediaSecrets(attachment.requireMediaName()), SignalStore.backup.mediaRootBackupKey.deriveMediaSecrets(attachment.requireMediaName()),
attachment.dataHash!!.decodeBase64OrThrow(), attachment.dataHash!!.decodeBase64OrThrow(),
cdnCredentials, cdnCredentials,
archiveFile, attachmentFile,
pointer, pointer,
maxReceiveSize, maxReceiveSize,
progressListener progressListener
@@ -295,9 +291,8 @@ class RestoreAttachmentJob private constructor(
SignalDatabase.attachments.finalizeAttachmentAfterDownload(messageId, attachmentId, decryptingStream, if (manual) System.currentTimeMillis().milliseconds else null) SignalDatabase.attachments.finalizeAttachmentAfterDownload(messageId, attachmentId, decryptingStream, if (manual) System.currentTimeMillis().milliseconds else null)
} catch (e: RangeException) { } catch (e: RangeException) {
val transferFile = archiveFile ?: attachmentFile Log.w(TAG, "[$attachmentId] Range exception, file size " + attachmentFile.length(), e)
Log.w(TAG, "[$attachmentId] Range exception, file size " + transferFile.length(), e) if (attachmentFile.delete()) {
if (transferFile.delete()) {
Log.i(TAG, "Deleted temp download file to recover") Log.i(TAG, "Deleted temp download file to recover")
throw RetryLaterException(e) throw RetryLaterException(e)
} else { } else {

View File

@@ -75,7 +75,7 @@ class PartDataSource implements DataSource {
final byte[] decodedKey = Base64.decode(attachmentKey); final byte[] decodedKey = Base64.decode(attachmentKey);
if (attachment.transferState == AttachmentTable.TRANSFER_RESTORE_IN_PROGRESS && attachment.archiveTransferState == AttachmentTable.ArchiveTransferState.FINISHED) { if (attachment.transferState == AttachmentTable.TRANSFER_RESTORE_IN_PROGRESS && attachment.archiveTransferState == AttachmentTable.ArchiveTransferState.FINISHED) {
final File archiveFile = attachmentDatabase.getOrCreateArchiveTransferFile(attachment.attachmentId); final File archiveFile = attachmentDatabase.getOrCreateTransferFile(attachment.attachmentId);
try { try {
String mediaName = DatabaseAttachmentArchiveUtil.requireMediaNameAsString(attachment); String mediaName = DatabaseAttachmentArchiveUtil.requireMediaNameAsString(attachment);
String mediaId = MediaName.toMediaIdString(mediaName, SignalStore.backup().getMediaRootBackupKey()); String mediaId = MediaName.toMediaIdString(mediaName, SignalStore.backup().getMediaRootBackupKey());