mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
fix(logs): wait for the ended session's log collection before sharing it
This commit is contained in:
1 parent
312069603a
commit
5466f23764
3 files changed
+65
-3
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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<File?> { 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<File?> { 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")
|
||||
|
||||
Reference in new issue
Block a user