From 2cce33d6f860efc5648a14b2ada3565678b3c02d Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:53:06 +0300 Subject: [PATCH] Keep the install record out of update merges and drop update results that went stale mid-check --- .../com/droiddeck/launcher/stores/itch/ItchStaging.kt | 6 ++++-- .../com/droiddeck/launcher/stores/itch/ItchUpdates.kt | 4 ++++ .../droiddeck/launcher/stores/itch/ItchStagingTest.kt | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt index df7258cb74..73e8f85961 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt @@ -5,13 +5,15 @@ import java.nio.file.Files internal object ItchStaging { const val DIR = ".droiddeck-update" + const val RECORD = ".droiddeck-store.json" - fun merge(from: File, to: File) { + fun merge(from: File, to: File, top: Boolean = true) { for (child in from.listFiles().orEmpty()) { + if (top && child.name == RECORD) continue val dest = File(to, child.name) val destPath = dest.toPath() if (child.isDirectory && !Files.isSymbolicLink(child.toPath()) && dest.isDirectory && !Files.isSymbolicLink(destPath)) { - merge(child, dest) + merge(child, dest, false) continue } if (Files.isSymbolicLink(destPath) || dest.exists()) { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt index d255c790e4..e178ed5a24 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt @@ -94,10 +94,12 @@ internal object ItchUpdates { StoresState.post { total = games.size; done = 0; checking = true } val found = LinkedHashMap() val answered = HashSet() + val snapshot = HashMap>() var failed = false games.forEachIndexed { i, game -> if (i > 0) Thread.sleep(GAP_MS) val extra = game.sidecar.extra + snapshot[game.key] = game.sidecar.installVersion to extra["uploadId"].orEmpty() val gameId = extra["gameId"].orEmpty() if (gameId.isNotEmpty()) { val uploads = ItchApi.uploads(key, gameId, extra["downloadKeyId"].orEmpty()) @@ -113,6 +115,8 @@ internal object ItchUpdates { StoresState.post { if (started != generation) return@post for (k in answered) { + val now = StoresState.installed.firstOrNull { it.key == k } ?: continue + if (snapshot[k] != now.sidecar.installVersion to now.sidecar.extra["uploadId"].orEmpty()) continue val u = found[k] if (u != null) available[k] = u else available.remove(k) } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt index 918c62d8f7..226ef3b9b0 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt @@ -71,4 +71,15 @@ class ItchStagingTest { assertFalse(File(outside, "level.dat").exists()) assertEquals("new", File(game, "data/level.dat").readText()) } + + @Test fun theInstallRecordIsNeverReplacedByTheArchive() { + val game = tmp.newFolder("game") + val staged = tmp.newFolder("staged") + file(game, ".droiddeck-store.json", "record") + file(staged, ".droiddeck-store.json", "forged") + file(staged, "sub/.droiddeck-store.json", "nested") + ItchStaging.merge(staged, game) + assertEquals("record", File(game, ".droiddeck-store.json").readText()) + assertEquals("nested", File(game, "sub/.droiddeck-store.json").readText()) + } }