diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index c9c55f9c27..ba180e8204 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -205,6 +205,7 @@ internal object EnhancedSessionLogShare { limits.maxFilesPerArchive < 1 || limits.maxBytesPerFile < 1 || limits.maxBytesTotal < 1) { return emptyList() } + SessionArtifacts.awaitCollections(dir = folder) val out = SessionLogShare.shareDir(context).apply { deleteRecursively(); mkdirs() } val stageLease = acquireDiagnosticStage(context, out.name) val stage = stageLease.directory @@ -265,6 +266,7 @@ internal object EnhancedSessionLogShare { limits.maxFilesPerArchive < 1 || limits.maxBytesPerFile < 1 || limits.maxBytesTotal < 1) { return null } + SessionArtifacts.awaitCollections(dir = folder) val out = outputDirectory.apply { deleteRecursively(); mkdirs() } val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = true) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 68cb9b4976..7916e45798 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -36,7 +36,7 @@ object SessionArtifacts { try { collecting.add(dir) } finally { collectingLock.unlock() } } - private fun collectionDone(dir: File) { + internal fun collectionDone(dir: File) { collectingLock.lock() try { collecting.remove(dir); collectingDone.signalAll() } finally { collectingLock.unlock() } } @@ -46,11 +46,14 @@ object SessionArtifacts { try { return dir in collecting } finally { collectingLock.unlock() } } - fun awaitCollections(timeoutMs: Long = 30_000) { + fun awaitCollections(timeoutMs: Long = 30_000, dir: File? = null) { + val target = dir?.absoluteFile?.normalize() collectingLock.lock() try { var left = java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(timeoutMs) - while (collecting.isNotEmpty() && left > 0) left = collectingDone.awaitNanos(left) + while (left > 0 && (if (target == null) collecting.isNotEmpty() else collecting.any { it.absoluteFile.normalize() == target })) { + left = collectingDone.awaitNanos(left) + } } finally { collectingLock.unlock() } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index 087c1a9980..741d32a3de 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -6,10 +6,14 @@ import java.text.SimpleDateFormat import java.util.UUID import java.util.Date import java.util.Locale +import java.util.concurrent.Executors import java.util.concurrent.TimeUnit +import java.util.concurrent.TimeoutException import java.util.zip.ZipFile import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertThrows import org.junit.Assert.assertTrue import org.junit.After import org.junit.Before @@ -87,6 +91,59 @@ class SessionLogShareZipTest { } } + @Test fun aShareWaitsForTheEndedSessionsLogCollection() { + SessionLogShare.clear(app) + val session = File(LinuxRuntime.logDir(app), "2026-12-03-01-steam").apply { mkdirs() } + val pool = Executors.newSingleThreadExecutor() + try { + File(session, "session.log").writeText("booted\n") + SessionArtifacts.collectionStarted(session) + val zip = pool.submit { zipOnThisThread(File(session.path)) } + assertThrows(TimeoutException::class.java) { zip.get(500, TimeUnit.MILLISECONDS) } + File(session, "steam").mkdirs() + File(session, "steam/content_log.txt").writeText("AppID 550 App update changed : Running Update,Preallocating,\n") + SessionArtifacts.collectionDone(session) + ZipFile(zip.get(20, TimeUnit.SECONDS)!!).use { archive -> + assertNotNull(archive.getEntry("${session.name}/steam/content_log.txt")) + } + } finally { + SessionArtifacts.collectionDone(session) + pool.shutdownNow() + SessionLogShare.clear(app) + session.deleteRecursively() + } + } + + @Test fun aShareDoesNotWaitForAnotherSessionsCollection() { + SessionLogShare.clear(app) + val session = File(LinuxRuntime.logDir(app), "2026-12-03-02-steam").apply { mkdirs() } + val other = File(LinuxRuntime.logDir(app), "2026-12-03-03-steam").apply { mkdirs() } + val pool = Executors.newSingleThreadExecutor() + try { + File(session, "session.log").writeText("booted\n") + SessionArtifacts.collectionStarted(other) + val zip = pool.submit { zipOnThisThread(session) } + ZipFile(zip.get(20, TimeUnit.SECONDS)!!).use { archive -> + assertNotNull(archive.getEntry("${session.name}/session.log")) + } + } finally { + SessionArtifacts.collectionDone(other) + pool.shutdownNow() + SessionLogShare.clear(app) + session.deleteRecursively() + other.deleteRecursively() + } + } + + private fun zipOnThisThread(session: File): File? { + installJvmSecureSourceOpener() + try { + return SessionLogShare.zipFolder(app, session) + } finally { + resetSecureSourceOpener() + } + } + @Test fun aLargeSteamLogIsRedactedInTheSharedArchive() { val session = File(LinuxRuntime.logDir(app), "2026-10-08-02-steam").apply { mkdirs() } val raw = File(session, "steam-42.log")