From 65a30cf2a7cc8ccdf377ff20a5ac07eed17f0eee Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Fri, 20 Feb 2026 19:18:51 +0000 Subject: [PATCH] Mark attachment 404's as permanent failures. --- .../thoughtcrime/securesms/attachments/Attachment.kt | 2 +- .../securesms/jobs/RestoreAttachmentJob.kt | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/attachments/Attachment.kt b/app/src/main/java/org/thoughtcrime/securesms/attachments/Attachment.kt index 3a9866cc01..0370ae022b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/attachments/Attachment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/attachments/Attachment.kt @@ -153,7 +153,7 @@ abstract class Attachment( * Denotes whether the media for the given attachment is no longer available for download. */ val isMediaNoLongerAvailableForDownload: Boolean - get() = isPermanentlyFailed && uploadTimestamp.milliseconds > 30.days + get() = isPermanentlyFailed && (System.currentTimeMillis().milliseconds - uploadTimestamp.milliseconds) > 30.days val isSticker: Boolean get() = stickerLocator != null 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 5a7b16c0a6..c3dbb001ab 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/RestoreAttachmentJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/RestoreAttachmentJob.kt @@ -441,6 +441,8 @@ class RestoreAttachmentJob private constructor( if (attachment.dataHash != null) { maybePostFailedToDownloadFromArchiveAndTransitNotification() } + markPermanentlyFailed(attachmentId) + return } else if (SignalStore.backup.backsUpMedia && attachment.remoteLocation.isNotNullOrBlank()) { Log.w(TAG, "[$attachmentId] Failed to download attachment from the archive CDN! Retrying download from transit CDN. hasPlaintextHash: ${attachment.dataHash != null}") if (attachment.dataHash != null) { @@ -453,8 +455,12 @@ class RestoreAttachmentJob private constructor( if (attachment.dataHash != null) { maybePostFailedToDownloadFromArchiveAndTransitNotification() } + markPermanentlyFailed(attachmentId) + return } else if (attachment.remoteLocation.isNotNullOrBlank()) { Log.w(TAG, "[$attachmentId] Failed to restore an attachment for a free tier user. Likely just older than 45 days.") + markPermanentlyFailed(attachmentId) + return } } 401 -> { @@ -491,9 +497,9 @@ class RestoreAttachmentJob private constructor( SignalDatabase.attachments.clearIncrementalMacsForAttachmentAndAnyDuplicates(attachmentId, attachment.remoteKey, attachment.dataHash) } markFailed(attachmentId) + } finally { + attachmentFile.delete() } - - attachmentFile.delete() } private fun markFailed(attachmentId: AttachmentId) {