From 30e43e99fc12fee01c99652624ee934f20ced41d Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 2 Dec 2025 14:52:16 -0500 Subject: [PATCH] Guard against invalid attachment states when copying to archive. Fixes #14461 --- .../jobs/CopyAttachmentToArchiveJob.kt | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/CopyAttachmentToArchiveJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/CopyAttachmentToArchiveJob.kt index 8b981a3e9c..a0adb23d28 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/CopyAttachmentToArchiveJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/CopyAttachmentToArchiveJob.kt @@ -123,9 +123,18 @@ class CopyAttachmentToArchiveJob private constructor(private val attachmentId: A return Result.success() } - if (isCanceled) { - Log.w(TAG, "[$attachmentId] Canceled. Refusing to proceed.") - return Result.failure() + if (attachment.cdn !in ALLOWED_SOURCE_CDNS) { + Log.i(TAG, "[$attachmentId] Attachment CDN (${attachment.cdn}) is not in allowed source CDNs. Enqueueing an upload job instead.") + setArchiveTransferStateWithDelayedNotification(attachmentId, AttachmentTable.ArchiveTransferState.NONE) + AppDependencies.jobManager.add(UploadAttachmentToArchiveJob(attachmentId, canReuseUpload = false)) + return Result.success() + } + + if (attachment.remoteLocation == null) { + Log.i(TAG, "[$attachmentId] Attachment has no remote location. Enqueueing an upload job instead.") + setArchiveTransferStateWithDelayedNotification(attachmentId, AttachmentTable.ArchiveTransferState.NONE) + AppDependencies.jobManager.add(UploadAttachmentToArchiveJob(attachmentId, canReuseUpload = false)) + return Result.success() } if (attachment.archiveTransferState == AttachmentTable.ArchiveTransferState.NONE) { @@ -134,6 +143,11 @@ class CopyAttachmentToArchiveJob private constructor(private val attachmentId: A return Result.success() } + if (isCanceled) { + Log.w(TAG, "[$attachmentId] Canceled. Refusing to proceed.") + return Result.failure() + } + val result = when (val archiveResult = BackupRepository.copyAttachmentToArchive(attachment)) { is NetworkResult.Success -> { Log.i(TAG, "[$attachmentId] Successfully copied the archive tier.")