mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Remove archive_transfer_file column.
This commit is contained in:
committed by
Cody Henthorne
parent
03dc014c08
commit
b1063f69f9
@@ -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)
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user