fix(logs): Share logs keeps the running session's game log when Steam's own logs are large (#3397)

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
The412BannerandKurt Himebauch authored and GitHub committed 2026-12-05 12:54:57 -05:00
1 parent 9d7821f120
commit eaa64597e0
2 files changed
+57 -9

No files matched your search

@@ -697,15 +697,6 @@ internal object EnhancedSessionLogShare {
Category.GAMES, "DROIDDECK_DIAGNOSTICS event=game_",
)
}
if (SessionPaths.current()?.canonicalFile == folder.canonicalFile && !File(folder, "steam").exists()) {
val steam = File(SessionPrefs.activeSteamRoot(context), "logs")
val scan = directFiles(steam, remaining(maxFiles, out.size))
truncated = truncated || scan.truncated
partial = partial || scan.partial
scan.files.forEach {
add(it, steam, "${folder.name}/steam/${it.name}", "live-steam")
}
}
val logs = LinuxRuntime.logDir(context)
for ((name, root) in listOf(SessionLogShare.STORES_DIR to File(logs, SessionLogShare.STORES_DIR), SessionPaths.TOOLS_DIR to File(logs, SessionPaths.TOOLS_DIR))) {
val scan = directFiles(root, STORE_LOG_SCAN)
@@ -742,6 +733,15 @@ internal object EnhancedSessionLogShare {
if (relative == EnhancedDiagnostics.MANIFEST_FILE) return@forEach
add(file, folder, "${folder.name}/$relative", "session")
}
if (SessionPaths.current()?.canonicalFile == folder.canonicalFile && !File(folder, "steam").exists()) {
val steam = File(SessionPrefs.activeSteamRoot(context), "logs")
val scan = directFiles(steam, remaining(maxFiles, out.size))
truncated = truncated || scan.truncated
partial = partial || scan.partial
scan.files.forEach {
add(it, steam, "${folder.name}/steam/${it.name}", "live-steam")
}
}
return CollectionResult(out.values.toList(), truncated, partial)
}
@@ -14,6 +14,7 @@ import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
import java.io.IOException
import java.io.RandomAccessFile
import java.nio.ByteBuffer
@@ -436,6 +437,53 @@ class EnhancedSessionLogShareTest {
SessionLogShare.clear(app)
}
@Test fun theRunningSessionsGameLogIsSharedBeforeSteamsWholeClientLogs() {
val previousLogsEnabled = SessionPrefs.logsEnabled(app)
val steamLog = File(SessionPrefs.activeSteamRoot(app), "logs/console_log.txt")
var started: File? = null
try {
SessionPrefs.setLogsEnabled(app, true)
val session = SessionPaths.beginOrCurrent(app, "live-steam").also { started = it }
session.resolve("session.log").writeText("session\n")
session.resolve("steam-239250.log").writeText("wine: game log\n")
steamLog.apply { parentFile!!.mkdirs(); writeText("steam client history\n".repeat(400)) }
val limits = EnhancedShareLimits(maxFilesPerArchive = 16, maxBytesPerFile = 8192, maxBytesTotal = 4096)
val zip = EnhancedSessionLogShare.createLegacy(app, session, limits = limits)!!
ZipFile(zip).use { archive ->
assertEquals(
"wine: game log\n",
archive.getInputStream(archive.getEntry("${session.name}/steam-239250.log")).bufferedReader().readText(),
)
val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json"))
.bufferedReader().readText())
val entries = manifest.getJSONArray("entries")
val records = (0 until entries.length()).map { entries.getJSONObject(it) }
assertEquals("captured", records.single { it.optString("entry") == "${session.name}/steam-239250.log" }.getString("status"))
val steam = records.single { it.optString("entry") == "${session.name}/steam/console_log.txt" }
assertEquals("live-steam", steam.getString("origin"))
assertEquals("truncated", steam.getString("status"))
assertTrue(archive.getEntry("${session.name}/steam/console_log.txt") != null)
}
val roomy = EnhancedSessionLogShare.createLegacy(app, session)!!
ZipFile(roomy).use { archive ->
assertEquals(
"steam client history\n".repeat(400),
archive.getInputStream(archive.getEntry("${session.name}/steam/console_log.txt")).bufferedReader().readText(),
)
}
} finally {
SessionPaths.take()?.let { SessionPaths.release(app, it) }
started?.deleteRecursively()
steamLog.delete()
SessionPrefs.setLogsEnabled(app, previousLogsEnabled)
SessionLogShare.clear(app)
}
}
@Test fun unreadableDiscoverySubtreeKeepsOtherLogsAndMarksTheManifestPartial() {
assumeFilePermissionsEnforced()
assumeFalse(System.getProperty("os.name").startsWith("Windows"))