fix: games on an SD card install faster and Battle.net can read the card's volume (#2379)

A Battle.net library on another volume is reached through its own drive letter, so the Agent's volume query succeeds. The proot fast path keeps folder handles for FUSE-backed libraries. Supersedes #2377.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-11 19:10:49 -05:00
1 parent 1d247d212b
commit 3b6d13a8d7
6 files changed
+883 -36

No files matched your search

@@ -232,11 +232,24 @@ object BattleNet {
}
internal fun hostFolder(context: Context, path: String): File? {
val drive = Regex("""^([CcZz]):[\\/](.*)$""").matchEntire(path.trim()) ?: return null
val drive = Regex("""^([A-Za-z]):[\\/](.*)$""").matchEntire(path.trim()) ?: return null
val relative = drive.groupValues[2].replace('\\', '/').trim('/')
if (relative.isEmpty() || relative.split('/').any { it == ".." }) return null
return if (drive.groupValues[1].equals("c", ignoreCase = true)) File(prefix(context), "pfx/drive_c/$relative")
else com.droiddeck.launcher.frontend.AddedGames.hostPath(context, "/$relative")
val letter = drive.groupValues[1].lowercase()
if (letter == "c") return File(prefix(context), "pfx/drive_c/$relative")
val link = File(prefix(context), "pfx/dosdevices/$letter:").toPath()
val mapped = runCatching { java.nio.file.Files.readSymbolicLink(link).toString() }.getOrNull()
val target = when {
mapped == null -> if (letter == "z") "/" else return null
mapped.startsWith("/") -> mapped
else -> {
val rootfs = LinuxRuntime.rootDir(context).toPath().toAbsolutePath().normalize()
val resolved = link.toAbsolutePath().parent.resolve(mapped).normalize()
if (!resolved.startsWith(rootfs)) return null
"/" + rootfs.relativize(resolved).joinToString("/")
}
}.trimEnd('/')
return com.droiddeck.launcher.frontend.AddedGames.hostPath(context, "$target/$relative")
}
private val KEY = Regex("""^\[(.+)\](?:\s+\d+)?\s*$""")
@@ -259,6 +259,29 @@ class BattleNetTest {
BattleNet.hostFolder(context, "Z:/root/Games/Stores/Battle.net/Hearthstone/"))
}
@Test fun aMappedWineDriveResolvesThroughItsLink() {
val devices = File(BattleNet.prefix(context), "pfx/dosdevices").apply { mkdirs() }
java.nio.file.Files.createSymbolicLink(File(devices, "d:").toPath(), java.nio.file.Paths.get("/root/Games/Card"))
java.nio.file.Files.createSymbolicLink(File(devices, "e:").toPath(), java.nio.file.Paths.get("../drive_c"))
assertEquals(File(LinuxRuntime.rootDir(context), "root/Games/Card/Battle.net/Hearthstone"),
BattleNet.hostFolder(context, "D:\\Battle.net\\Hearthstone"))
assertEquals(File(BattleNet.prefix(context), "pfx/drive_c/Games/X"), BattleNet.hostFolder(context, "E:\\Games\\X"))
assertNull(BattleNet.hostFolder(context, "F:\\Games\\X"))
assertNull(BattleNet.hostFolder(context, "D:\\..\\etc"))
}
@Test fun aDriveLinkTheNativeUserlandMadeRelativeStillResolvesInTheGuest() {
val root = LinuxRuntime.rootDir(context)
val devices = File(BattleNet.prefix(context), "pfx/dosdevices").apply { mkdirs() }
java.nio.file.Files.createSymbolicLink(File(devices, "d:").toPath(), java.nio.file.Paths.get("/root/Games/Card"))
java.nio.file.Files.createSymbolicLink(File(devices, "g:").toPath(), java.nio.file.Paths.get("../../../../../../../../../../.."))
NativeGuest.relinkAbsoluteSymlinks(context, root)
assertFalse(java.nio.file.Files.readSymbolicLink(File(devices, "d:").toPath()).isAbsolute)
assertEquals(File(root, "root/Games/Card/Battle.net/Hearthstone"),
BattleNet.hostFolder(context, "D:\\Battle.net\\Hearthstone"))
assertNull(BattleNet.hostFolder(context, "G:\\etc\\passwd"))
}
@Test fun wowForeverIsListedBesideRetailInTheSharedWorldOfWarcraftFolder() {
val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() }