Fix handling of missing files during archive upload.

This commit is contained in:
Greyson Parrelli
2025-03-28 10:40:08 -04:00
parent d1accfff82
commit f48a13afc0
2 changed files with 29 additions and 9 deletions

View File

@@ -308,11 +308,7 @@ class AttachmentTable(
@Throws(IOException::class)
fun getAttachmentStream(attachmentId: AttachmentId, offset: Long): InputStream {
return try {
getDataStream(attachmentId, offset)
} catch (e: FileNotFoundException) {
throw IOException("No stream for: $attachmentId", e)
} ?: throw IOException("No stream for: $attachmentId")
return getDataStream(attachmentId, offset) ?: throw FileNotFoundException("No stream for: $attachmentId")
}
@Throws(IOException::class)
@@ -671,6 +667,26 @@ class AttachmentTable(
}
}
/**
* Sets the archive transfer state for the given attachment and all other attachments that share the same data file.
*/
fun setArchiveTransferStateUnlessPermanentFailure(id: AttachmentId, state: ArchiveTransferState) {
writableDatabase.withinTransaction {
val dataFile: String = readableDatabase
.select(DATA_FILE)
.from(TABLE_NAME)
.where("$ID = ?", id.id)
.run()
.readToSingleObject { it.requireString(DATA_FILE) } ?: return@withinTransaction
writableDatabase
.update(TABLE_NAME)
.values(ARCHIVE_TRANSFER_STATE to state.value)
.where("$DATA_FILE = ? AND $ARCHIVE_TRANSFER_STATE != ${ArchiveTransferState.PERMANENT_FAILURE.value}", dataFile)
.run()
}
}
/**
* Marks eligible attachments as offloaded based on their received at timestamp, their last restore time,
* presence of thumbnail if media, and the full file being available in the archive.