mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Fix handling of missing files during archive upload.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user