Fix extraneous incremental chunk sizes.
This commit is contained in:
parent
ed24fd0c4b
commit
ea38376c3a
4 changed files with 56 additions and 11 deletions
|
@ -2236,8 +2236,6 @@ class AttachmentTable(
|
|||
put(CDN_NUMBER, attachment.cdn.serialize())
|
||||
put(REMOTE_LOCATION, attachment.remoteLocation)
|
||||
put(REMOTE_DIGEST, attachment.remoteDigest)
|
||||
put(REMOTE_INCREMENTAL_DIGEST, attachment.incrementalDigest)
|
||||
put(REMOTE_INCREMENTAL_DIGEST_CHUNK_SIZE, attachment.incrementalMacChunkSize)
|
||||
put(REMOTE_KEY, attachment.remoteKey)
|
||||
put(FILE_NAME, StorageUtil.getCleanFileName(attachment.fileName))
|
||||
put(DATA_SIZE, attachment.size)
|
||||
|
@ -2259,6 +2257,13 @@ class AttachmentTable(
|
|||
put(STICKER_ID, sticker.stickerId)
|
||||
put(STICKER_EMOJI, sticker.emoji)
|
||||
}
|
||||
|
||||
if (attachment.incrementalDigest?.isNotEmpty() == true && attachment.incrementalMacChunkSize != 0) {
|
||||
put(REMOTE_INCREMENTAL_DIGEST, attachment.incrementalDigest)
|
||||
put(REMOTE_INCREMENTAL_DIGEST_CHUNK_SIZE, attachment.incrementalMacChunkSize)
|
||||
} else {
|
||||
putNull(REMOTE_INCREMENTAL_DIGEST)
|
||||
}
|
||||
}
|
||||
|
||||
val rowId = db.insert(TABLE_NAME, null, contentValues)
|
||||
|
@ -2288,8 +2293,6 @@ class AttachmentTable(
|
|||
put(CDN_NUMBER, attachment.cdn.serialize())
|
||||
put(REMOTE_LOCATION, attachment.remoteLocation)
|
||||
put(REMOTE_DIGEST, attachment.remoteDigest)
|
||||
put(REMOTE_INCREMENTAL_DIGEST, attachment.incrementalDigest)
|
||||
put(REMOTE_INCREMENTAL_DIGEST_CHUNK_SIZE, attachment.incrementalMacChunkSize)
|
||||
put(REMOTE_KEY, attachment.remoteKey)
|
||||
put(FILE_NAME, StorageUtil.getCleanFileName(attachment.fileName))
|
||||
put(DATA_SIZE, attachment.size)
|
||||
|
@ -2317,6 +2320,13 @@ class AttachmentTable(
|
|||
put(STICKER_ID, sticker.stickerId)
|
||||
put(STICKER_EMOJI, sticker.emoji)
|
||||
}
|
||||
|
||||
if (attachment.incrementalDigest?.isNotEmpty() == true && attachment.incrementalMacChunkSize != 0) {
|
||||
put(REMOTE_INCREMENTAL_DIGEST, attachment.incrementalDigest)
|
||||
put(REMOTE_INCREMENTAL_DIGEST_CHUNK_SIZE, attachment.incrementalMacChunkSize)
|
||||
} else {
|
||||
putNull(REMOTE_INCREMENTAL_DIGEST)
|
||||
}
|
||||
}
|
||||
|
||||
val rowId = db.insert(TABLE_NAME, null, contentValues)
|
||||
|
@ -2437,8 +2447,6 @@ class AttachmentTable(
|
|||
contentValues.put(CDN_NUMBER, uploadTemplate?.cdn?.serialize() ?: Cdn.CDN_0.serialize())
|
||||
contentValues.put(REMOTE_LOCATION, uploadTemplate?.remoteLocation)
|
||||
contentValues.put(REMOTE_DIGEST, uploadTemplate?.remoteDigest)
|
||||
contentValues.put(REMOTE_INCREMENTAL_DIGEST, uploadTemplate?.incrementalDigest)
|
||||
contentValues.put(REMOTE_INCREMENTAL_DIGEST_CHUNK_SIZE, uploadTemplate?.incrementalMacChunkSize ?: 0)
|
||||
contentValues.put(REMOTE_KEY, uploadTemplate?.remoteKey)
|
||||
contentValues.put(REMOTE_IV, uploadTemplate?.remoteIv)
|
||||
contentValues.put(FILE_NAME, StorageUtil.getCleanFileName(attachment.fileName))
|
||||
|
@ -2454,6 +2462,13 @@ class AttachmentTable(
|
|||
contentValues.put(TRANSFORM_PROPERTIES, transformProperties.serialize())
|
||||
contentValues.put(ATTACHMENT_UUID, attachment.uuid?.toString())
|
||||
|
||||
if (uploadTemplate?.incrementalDigest?.isNotEmpty() == true && uploadTemplate.incrementalMacChunkSize != 0) {
|
||||
contentValues.put(REMOTE_INCREMENTAL_DIGEST, uploadTemplate.incrementalDigest)
|
||||
contentValues.put(REMOTE_INCREMENTAL_DIGEST_CHUNK_SIZE, uploadTemplate.incrementalMacChunkSize)
|
||||
} else {
|
||||
contentValues.putNull(REMOTE_INCREMENTAL_DIGEST)
|
||||
}
|
||||
|
||||
if (attachment.transformProperties?.videoTrimStartTimeUs != 0L) {
|
||||
contentValues.putNull(BLUR_HASH)
|
||||
} else {
|
||||
|
|
|
@ -112,6 +112,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V252_AttachmentOffl
|
|||
import org.thoughtcrime.securesms.database.helpers.migration.V253_CreateChatFolderTables
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V254_AddChatFolderConstraint
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V255_AddCallTableLogIndex
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V256_FixIncrementalDigestColumns
|
||||
|
||||
/**
|
||||
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
|
||||
|
@ -226,10 +227,11 @@ object SignalDatabaseMigrations {
|
|||
252 to V252_AttachmentOffloadRestoredAtColumn,
|
||||
253 to V253_CreateChatFolderTables,
|
||||
254 to V254_AddChatFolderConstraint,
|
||||
255 to V255_AddCallTableLogIndex
|
||||
255 to V255_AddCallTableLogIndex,
|
||||
256 to V256_FixIncrementalDigestColumns
|
||||
)
|
||||
|
||||
const val DATABASE_VERSION = 255
|
||||
const val DATABASE_VERSION = 256
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package org.thoughtcrime.securesms.database.helpers.migration
|
||||
|
||||
import android.app.Application
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* Fixes a bug where sometimes incremental chunk size would be set when the attachment was not actually incremental
|
||||
* Clears out any cases where only one of the incremental_digest / incremental_size fields were previously set
|
||||
*/
|
||||
@Suppress("ClassName")
|
||||
object V256_FixIncrementalDigestColumns : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL(
|
||||
"""
|
||||
UPDATE attachment
|
||||
SET
|
||||
remote_incremental_digest = NULL,
|
||||
remote_incremental_digest_chunk_size = 0
|
||||
WHERE
|
||||
remote_incremental_digest IS NULL OR
|
||||
LENGTH(remote_incremental_digest) = 0 OR
|
||||
remote_incremental_digest_chunk_size = 0
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@ class DigestingRequestBody(
|
|||
|
||||
outputStream.flush()
|
||||
|
||||
val incrementalDigest: ByteArray = if (isIncremental) {
|
||||
val incrementalDigest: ByteArray? = if (isIncremental) {
|
||||
if (contentLength != outputStream.totalBytesWritten) {
|
||||
Log.w(TAG, "Content uploaded ${logMessage(outputStream.totalBytesWritten, contentLength)} bytes compared to expected!")
|
||||
} else {
|
||||
|
@ -73,10 +73,12 @@ class DigestingRequestBody(
|
|||
digestStream.close()
|
||||
digestStream.toByteArray()
|
||||
} else {
|
||||
ByteArray(0)
|
||||
null
|
||||
}
|
||||
|
||||
attachmentDigest = AttachmentDigest(outputStream.transmittedDigest, incrementalDigest, sizeChoice.sizeInBytes)
|
||||
val incrementalDigestChunkSize: Int = if (incrementalDigest?.isNotEmpty() == true) sizeChoice.sizeInBytes else 0
|
||||
|
||||
attachmentDigest = AttachmentDigest(outputStream.transmittedDigest, incrementalDigest, incrementalDigestChunkSize)
|
||||
}
|
||||
|
||||
override fun contentLength(): Long {
|
||||
|
|
Loading…
Add table
Reference in a new issue