mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +02:00
fix(diagnostics): stabilize pending crash ordering
This commit is contained in:
@@ -31,10 +31,13 @@ private class JvmPendingCrashStore(
|
||||
return directory
|
||||
.listFiles { file -> file.isFile && file.name.endsWith(".crash") }
|
||||
.orEmpty()
|
||||
.sortedByDescending { it.lastModified() }
|
||||
.mapNotNull { file ->
|
||||
runCatching { CrashReportCodec.decode(file.readText(StandardCharsets.UTF_8)) }.getOrNull()
|
||||
}
|
||||
.sortedWith(
|
||||
compareByDescending<CrashReport> { it.timestampMillis }
|
||||
.thenBy { it.id },
|
||||
)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -64,7 +67,10 @@ private class JvmPendingCrashStore(
|
||||
file to report
|
||||
}
|
||||
}
|
||||
.sortedByDescending { (_, report) -> report.timestampMillis }
|
||||
.sortedWith(
|
||||
compareByDescending<Pair<File, CrashReport>> { (_, report) -> report.timestampMillis }
|
||||
.thenBy { (_, report) -> report.id },
|
||||
)
|
||||
reports.forEachIndexed { index, (file, report) ->
|
||||
if (index >= maxCount || report.timestampMillis < olderThanTimestampMillis) file.delete()
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.vnidrop.app.diagnostics
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.attribute.FileTime
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
@@ -24,6 +25,8 @@ class PendingCrashStoreJvmTest {
|
||||
File(directory, ".orphan.tmp").writeText("partial")
|
||||
store.write(current.copy(id = "../../escape"))
|
||||
val escapedPath = File(directory, "../../escape.crash").canonicalFile
|
||||
Files.setLastModifiedTime(File(directory, "${older.id}.crash").toPath(), FileTime.fromMillis(2_000))
|
||||
Files.setLastModifiedTime(File(directory, "${current.id}.crash").toPath(), FileTime.fromMillis(1_000))
|
||||
|
||||
assertEquals(
|
||||
listOf("replaced", "older"),
|
||||
|
||||
Reference in New Issue
Block a user