From b1063f69f9a3770d1faeae10b5a640e6055d1851 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 24 Jun 2025 09:28:44 -0400 Subject: [PATCH] Remove archive_transfer_file column. --- .../securesms/database/AttachmentTable.kt | 33 ------------------- .../helpers/SignalDatabaseMigrations.kt | 6 ++-- .../V281_RemoveArchiveTransferFile.kt | 19 +++++++++++ .../securesms/jobs/RestoreAttachmentJob.kt | 11 ++----- .../securesms/video/exo/PartDataSource.java | 2 +- 5 files changed, 27 insertions(+), 44 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V281_RemoveArchiveTransferFile.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt index d9ee392b94..961a4e7c72 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt @@ -216,7 +216,6 @@ class AttachmentTable( DATA_HASH_START, DATA_HASH_END, ARCHIVE_CDN, - ARCHIVE_TRANSFER_FILE, THUMBNAIL_FILE, THUMBNAIL_RESTORE_STATE, ARCHIVE_TRANSFER_STATE, @@ -260,7 +259,6 @@ class AttachmentTable( $DATA_HASH_START TEXT DEFAULT NULL, $DATA_HASH_END TEXT DEFAULT NULL, $ARCHIVE_CDN INTEGER DEFAULT NULL, - $ARCHIVE_TRANSFER_FILE TEXT DEFAULT NULL, $ARCHIVE_TRANSFER_STATE INTEGER DEFAULT ${ArchiveTransferState.NONE.value}, $THUMBNAIL_FILE TEXT DEFAULT NULL, $THUMBNAIL_RANDOM BLOB DEFAULT NULL, @@ -1203,7 +1201,6 @@ class AttachmentTable( values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE) values.put(TRANSFER_FILE, null as String?) values.put(TRANSFORM_PROPERTIES, TransformProperties.forSkipTransform().serialize()) - values.put(ARCHIVE_TRANSFER_FILE, null as String?) values.put(REMOTE_LOCATION, existingPlaceholder.remoteLocation) values.put(CDN_NUMBER, existingPlaceholder.cdn.serialize()) values.put(REMOTE_KEY, existingPlaceholder.remoteKey!!) @@ -1624,24 +1621,6 @@ class AttachmentTable( 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 { 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 { val contentType = cursor.requireString(CONTENT_TYPE) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt index 8e217c13a8..b9365c1560 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt @@ -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.V279_AddNotificationProfileForeignKey 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 /** @@ -275,10 +276,11 @@ object SignalDatabaseMigrations { 277 to V277_AddNotificationProfileStorageSync, 278 to V278_BackupSnapshotTableVersions, 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 fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V281_RemoveArchiveTransferFile.kt b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V281_RemoveArchiveTransferFile.kt new file mode 100644 index 0000000000..738d6298b7 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V281_RemoveArchiveTransferFile.kt @@ -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") + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/RestoreAttachmentJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/RestoreAttachmentJob.kt index 76fe5f09ca..58aa8e142b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/RestoreAttachmentJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/RestoreAttachmentJob.kt @@ -230,7 +230,6 @@ class RestoreAttachmentJob private constructor( ) { val maxReceiveSize: Long = RemoteConfig.maxAttachmentReceiveSizeBytes val attachmentFile: File = SignalDatabase.attachments.getOrCreateTransferFile(attachmentId) - var archiveFile: File? = null var useArchiveCdn = false if (attachment.remoteDigest == null && attachment.dataHash == null) { @@ -267,9 +266,6 @@ class RestoreAttachmentJob private constructor( } 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 messageReceiver @@ -277,7 +273,7 @@ class RestoreAttachmentJob private constructor( SignalStore.backup.mediaRootBackupKey.deriveMediaSecrets(attachment.requireMediaName()), attachment.dataHash!!.decodeBase64OrThrow(), cdnCredentials, - archiveFile, + attachmentFile, pointer, maxReceiveSize, progressListener @@ -295,9 +291,8 @@ class RestoreAttachmentJob private constructor( SignalDatabase.attachments.finalizeAttachmentAfterDownload(messageId, attachmentId, decryptingStream, if (manual) System.currentTimeMillis().milliseconds else null) } catch (e: RangeException) { - val transferFile = archiveFile ?: attachmentFile - Log.w(TAG, "[$attachmentId] Range exception, file size " + transferFile.length(), e) - if (transferFile.delete()) { + Log.w(TAG, "[$attachmentId] Range exception, file size " + attachmentFile.length(), e) + if (attachmentFile.delete()) { Log.i(TAG, "Deleted temp download file to recover") throw RetryLaterException(e) } else { diff --git a/app/src/main/java/org/thoughtcrime/securesms/video/exo/PartDataSource.java b/app/src/main/java/org/thoughtcrime/securesms/video/exo/PartDataSource.java index 200a12a081..77befdee02 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/video/exo/PartDataSource.java +++ b/app/src/main/java/org/thoughtcrime/securesms/video/exo/PartDataSource.java @@ -75,7 +75,7 @@ class PartDataSource implements DataSource { final byte[] decodedKey = Base64.decode(attachmentKey); 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 { String mediaName = DatabaseAttachmentArchiveUtil.requireMediaNameAsString(attachment); String mediaId = MediaName.toMediaIdString(mediaName, SignalStore.backup().getMediaRootBackupKey());