Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LEIP-223] Fix upload crash for json log files #303

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ interface AttachmentDao {
@Query("SELECT * FROM ${AttachmentTable.URI_PATH} WHERE ${BaseColumns.MEASUREMENT_ID} = :measurementId LIMIT 1")
suspend fun loadOneByMeasurementId(measurementId: Long): Attachment?

@Query("SELECT * FROM ${AttachmentTable.URI_PATH} WHERE ${BaseColumns.MEASUREMENT_ID} = :measurementId AND ${AttachmentTable.COLUMN_TYPE} = :type ORDER BY ${BaseColumns.TIMESTAMP} ASC")
suspend fun loadOneByMeasurementIdAndType(measurementId: Long, type: FileType): Attachment?

@Query("SELECT * FROM ${AttachmentTable.URI_PATH} WHERE ${BaseColumns.MEASUREMENT_ID} = :measurementId AND ${AttachmentTable.COLUMN_STATUS} = :status ORDER BY ${BaseColumns.TIMESTAMP} ASC")
suspend fun loadAllByMeasurementIdAndStatus(measurementId: Long, status: AttachmentStatus): List<Attachment>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AttachmentSerializer {
*/
fun readFrom(attachment: Attachment) {
val builder = de.cyface.protos.model.File.newBuilder()
require(attachment.type == FileType.CSV || attachment.type == FileType.JPG) { "Unsupported type: ${attachment.type}" }
require(attachment.type == FileType.CSV || attachment.type == FileType.JSON || attachment.type == FileType.JPG) { "Unsupported type: ${attachment.type}" }

// Ensure we only inject bytes from the correct file format version
// The current version of the file format used to persist attachment data. It's stored in each attachment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ object TransferFileSerializer {
val builder = de.cyface.protos.model.Measurement.newBuilder()
.setFormatVersion(MeasurementSerializer.TRANSFER_FILE_FORMAT_VERSION.toInt())
when (reference.type) {
FileType.CSV -> {
// TODO: zip all attachments
FileType.JSON, FileType.CSV -> {
builder.capturingLog = attachment
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ class SyncAdapter private constructor(
FileType.CSV -> {
Validate.isTrue(format == 1.toShort())
}
FileType.JSON -> {
Validate.isTrue(format == 1.toShort())
}
FileType.JPG -> {
Validate.isTrue(format == 1.toShort())
}
Expand Down Expand Up @@ -627,13 +630,18 @@ class SyncAdapter private constructor(

return runBlocking {
// Attachments
val logCount = persistence.attachmentDao!!.countByMeasurementIdAndType(measurement.id, FileType.CSV)
val csvCount = persistence.attachmentDao!!.countByMeasurementIdAndType(measurement.id, FileType.CSV)
val jsonCount = persistence.attachmentDao!!.countByMeasurementIdAndType(measurement.id, FileType.JSON)
val logCount = csvCount + jsonCount
val imageCount = persistence.attachmentDao!!.countByMeasurementIdAndType(measurement.id, FileType.JPG)
val allAttachments = persistence.attachmentDao!!.countByMeasurementId(measurement.id)
val unsupportedAttachments = allAttachments - logCount - imageCount
require(unsupportedAttachments == 0) { "Number of unsupported attachments: $unsupportedAttachments" }
require(unsupportedAttachments == 0) {
"Number of unsupported attachments: $unsupportedAttachments"
}
val filesSize = if (allAttachments > 0) {
val attachment = persistence.attachmentDao!!.loadOneByMeasurementId(measurement.id)
// TODO: support multiple attachments by zipping them
val attachment = persistence.attachmentDao!!.loadOneByMeasurementIdAndType(measurement.id, FileType.JSON)
val folderPath = File(attachment!!.path.parent.toUri())
getFolderSize(folderPath)
} else 0
Expand Down
Loading