mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-16 11:16:12 -04:00
fix(debug): Use human-readable UTC timestamp in debug session directory names
Parse creation time from the embedded filename timestamp instead of relying on filesystem attributes, which are non-deterministic and caused flaky test failures in CI.
This commit is contained in:
+20
-6
@@ -256,13 +256,27 @@ class DebugSessionManager @Inject constructor(
|
||||
return prefix + file.name.removeSuffix(".zip")
|
||||
}
|
||||
|
||||
private val TIMESTAMP_FORMAT = java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'")
|
||||
.withZone(java.time.ZoneOffset.UTC)
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun parseCreatedAt(file: File): Instant = try {
|
||||
val attrs = Files.readAttributes(file.toPath(), BasicFileAttributes::class.java)
|
||||
attrs.creationTime().toInstant()
|
||||
} catch (e: Exception) {
|
||||
log(TAG, WARN) { "Failed to read creation time for ${file.name}: ${e.message}" }
|
||||
Instant.ofEpochMilli(file.lastModified())
|
||||
internal fun parseCreatedAt(file: File): Instant {
|
||||
val name = file.name.removeSuffix(".zip")
|
||||
val parts = name.split("_")
|
||||
// Format: capod_{version}_{yyyyMMddTHHmmssZ}_{suffix}
|
||||
if (parts.size >= 3) {
|
||||
try {
|
||||
return TIMESTAMP_FORMAT.parse(parts[2], Instant::from)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
return try {
|
||||
val attrs = Files.readAttributes(file.toPath(), BasicFileAttributes::class.java)
|
||||
attrs.creationTime().toInstant()
|
||||
} catch (e: Exception) {
|
||||
log(TAG, WARN) { "Failed to read creation time for ${file.name}: ${e.message}" }
|
||||
Instant.ofEpochMilli(file.lastModified())
|
||||
}
|
||||
}
|
||||
|
||||
private fun computeDiskSize(file: File): Long {
|
||||
|
||||
@@ -98,7 +98,8 @@ class RecorderModule @Inject constructor(
|
||||
}
|
||||
|
||||
private fun createSessionDir(): File {
|
||||
val timestamp = System.currentTimeMillis()
|
||||
val timestamp = java.time.ZonedDateTime.now(java.time.ZoneOffset.UTC)
|
||||
.format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"))
|
||||
val installIdPrefix = installId.id.take(8)
|
||||
val dirName = "capod_${BuildConfigWrap.VERSION_NAME}_${timestamp}_$installIdPrefix"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user