Guard against invalid attachment states when copying to archive.

Fixes #14461
This commit is contained in:
Greyson Parrelli
2025-12-02 14:52:16 -05:00
committed by jeffrey-signal
parent 706d89db87
commit 30e43e99fc

View File

@@ -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.")