fix(games): never give an added folder the internal store guest path

An added folder named Stores was bound at /root/Games/Stores, over the
internal store install root. legacyRoots, used by bindFolder and the
games-folder migration, now gives such a folder a suffixed guest path,
so guestBinds mounts every added root again, matching guestPath and the
session binds.
This commit is contained in:
Kurt Himebauch committed 2026-11-11 15:41:59 +00:00
1 parent e939475200
commit fe7cbc702d
5 files changed
+41 -14

No files matched your search

@@ -63,7 +63,8 @@ object GamesFolderMigration {
val names = hosts.groupingBy { it.name.lowercase() }.eachCount()
return hosts.map { host ->
val name = host.name.ifEmpty { "games" }
val guestName = if ((names[name.lowercase()] ?: 0) > 1) name + "-" + "%08x".format(CRC32().apply { update(host.path.toByteArray()) }.value).take(4) else name
val clash = (names[name.lowercase()] ?: 0) > 1 || "${AddedGames.GUEST_DIR}/$name" == StoreInstallRoot.INTERNAL_GUEST
val guestName = if (clash) name + "-" + "%08x".format(CRC32().apply { update(host.path.toByteArray()) }.value).take(4) else name
AddedGames.Root(host, "${AddedGames.GUEST_DIR}/$guestName")
}
}
@@ -14,6 +14,7 @@ import java.util.zip.CRC32
object StoreInstallRoot {
const val SPACE_UNKNOWN = -1L
private const val INTERNAL = "root/Games/Stores"
const val INTERNAL_GUEST = "/$INTERNAL"
private const val ON_VOLUME = "Games"
const val GUEST_EXTERNAL = "/mnt/droiddeck-stores"
@@ -192,18 +193,13 @@ object StoreInstallRoot {
}
}
for (folder in AddedGames.roots(context)) {
if (!folder.host.isDirectory || !folder.host.canRead() || shadowsInternal(folder.guest)) continue
if (!folder.host.isDirectory || !folder.host.canRead()) continue
File(root, folder.guest.removePrefix("/")).mkdirs()
out += folder.host.path + ":" + folder.guest
}
return out
}
private fun shadowsInternal(guest: String): Boolean {
val internal = "/$INTERNAL"
return guest == internal || internal.startsWith("$guest/")
}
internal fun externalBindSpecs(roots: List<Pair<File, String>>, guestRoot: File): List<String> =
roots.mapNotNull { (host, guest) ->
if (!host.isDirectory || !host.canRead()) return@mapNotNull null
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.frontend
import com.droiddeck.launcher.assumeFilePermissionsEnforced
import android.os.Environment
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.StoreInstallRoot
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
@@ -366,6 +367,15 @@ class AddedExesTest {
assertEquals("$clash-2", guests.last())
}
@Test fun aFolderNamedStoresIsNotBoundOverTheInternalStoreRoot() {
noGamesFolders()
val stores = File(tmp.newFolder("card"), "Stores").apply { exe(File(this, "One/One.exe")) }
val result = AddedGames.addFolder(app, stores)
val guest = SessionPrefs.gameFolderBinds(app).single().second
assertTrue(guest != StoreInstallRoot.INTERNAL_GUEST && guest.startsWith("${AddedGames.GUEST_DIR}/Stores-"))
assertEquals("$guest/One/One.exe", result.added.single().guestExe)
}
@Test fun aRemovedSingleExeGameStaysOffUntilPickedAgain() {
noGamesFolders()
val pick = onStorage("Download/Celeste/Celeste.exe")
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.frontend
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.StoreGameSidecar
import com.droiddeck.launcher.stores.StoreInstallRoot
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -182,6 +183,18 @@ class GamesFolderMigrationTest {
assertEquals(listOf(pc.path to AddedGames.GUEST_DIR + "/PC"), binds)
}
@Test fun aMigratedFolderNamedStoresDoesNotTakeTheInternalStoreGuest() {
val stores = File(tmp.newFolder("card"), "Stores").apply { exe(this, "One/One.exe") }
val pc = tmp.newFolder("PC").apply { exe(this, "Two/Two.exe") }
SessionPrefs.setAddedGamesDirs(app, listOf(stores.path, pc.path))
GamesFolderMigration.run(app)
val binds = SessionPrefs.gameFolderBinds(app).toMap()
assertTrue(binds.getValue(stores.path) != StoreInstallRoot.INTERNAL_GUEST)
assertEquals(AddedGames.GUEST_DIR + "/PC", binds.getValue(pc.path))
val games = AddedGames.scan(app).associateBy { it.name }
assertEquals(binds.getValue(stores.path) + "/One/One.exe", games.getValue("One").guestExe)
}
@Test fun twoFoldersOfOneNameKeepTheirOwnGuestPaths() {
val a = File(tmp.newFolder("a"), "Games").apply { mkdirs() }
val b = File(tmp.newFolder("b"), "Games").apply { mkdirs() }
@@ -75,13 +75,20 @@ class GogInnoextractTest {
assertTrue(AddedGames.guestPath(app, folder)!!.startsWith("/root/Games/Stores/GOG/"))
}
@Test fun anAddedFolderNamedStoresDoesNotHideTheInternalInstallRoot() {
val shadow = File(app.filesDir, "extra/Stores").apply { mkdirs() }
val normal = File(app.filesDir, "extra/Library").apply { mkdirs() }
SessionPrefs.setGameFolderBinds(app, listOf(shadow.path to "/root/Games/Stores", normal.path to "/root/Games/Library"))
val binds = StoreInstallRoot.guestBinds(app)
assertTrue(binds.none { it.endsWith(":/root/Games/Stores") })
assertTrue(binds.contains("${normal.path}:/root/Games/Library"))
@Test fun anAddedFolderNamedStoresIsMountedWithoutHidingTheInternalInstallRoot() {
val drive = File(app.filesDir, "usb/Stores").apply { mkdirs() }
AddedGames.bindFolder(app, drive)
val guest = AddedGames.guestPath(app, drive)!!
assertTrue(guest != StoreInstallRoot.INTERNAL_GUEST && !guest.startsWith(StoreInstallRoot.INTERNAL_GUEST + "/"))
SessionPrefs.setDefaultStorageFolder(app, drive.path, "Stores")
val chosen = File(drive, "Games/GOG/Chosen")
assertTrue(AddedGames.guestPath(app, chosen)!!.startsWith("$guest/"))
assertExtractorSeesEveryPart(chosen, listOf("setup_1207658934.exe", "setup_1207658934-1.bin"))
val internal = File(StoreInstallRoot.internalRoot(app), "GOG/Internal")
installer(internal, listOf("setup_1207658935.exe"))
val internalGuest = AddedGames.guestPath(app, internal)!!
assertTrue(internalGuest.startsWith(StoreInstallRoot.INTERNAL_GUEST + "/GOG/"))
assertNull(hostOf("$internalGuest/setup_1207658935.exe", StoreInstallRoot.guestBinds(app)))
}
@Test fun aFailedExtractionReportsTheExtractorsOwnError() {