Compare commits

...
Author SHA1 Message Date
maxjivi05 85f871b75b test(steam): verify launched process CPU affinity 2026-11-30 22:19:53 -05:00
maxjivi05 62b8b2e5dd fix(steam): launch games when CPU affinity is refused 2026-11-30 14:17:42 -05:00
MaxsTechReview 54ca518553 fix(storage): a card library the session cannot open by its raw path is opened by its storage path (#3475)
A game storage folder saved as a raw volume path is opened through the volume's /storage path when only that one is usable, and its private directories are kept under either path. Battle.net is only given a library folder when the configured one is attached, so a missing card no longer moves its install folder to internal storage.
2026-11-30 12:00:05 -05:00
11 changed files with 156 additions and 25 deletions

No files matched your search

@@ -59,13 +59,18 @@ object GameStorage {
return when {
pref == SessionPrefs.GAME_STORAGE_OFF -> null
pref.isEmpty() -> options(context).firstOrNull()?.let { Option(it.name, it.path) }
else -> Option(SessionPrefs.gameStorageLabel(context), pref).takeIf { attached(File(pref)) }
else -> reachable(pref).let { path -> Option(SessionPrefs.gameStorageLabel(context), path).takeIf { attached(File(path)) } }
}
}
fun disconnected(context: Context): Boolean {
val pref = SessionPrefs.gameStorage(context)
return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(pref))
return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(reachable(pref)))
}
internal fun reachable(path: String, usable: (File) -> Boolean = { it.isDirectory && it.canWrite() }): String {
val alias = UsbLink.storagePath(path)
return if (alias != path && !usable(File(path)) && usable(File(alias))) alias else path
}
internal fun attached(
@@ -46,7 +46,16 @@ object SecondaryLibrary {
}
fun privateRoot(files: File, library: File): File {
val digest = MessageDigest.getInstance("SHA-256").digest(library.canonicalPath.toByteArray())
val own = privateDir(files, library.canonicalPath)
if (own.exists()) return own
val raw = UsbLink.rawPath(library.absolutePath)
val alias = if (raw != library.absolutePath) raw else UsbLink.storagePath(library.absolutePath)
if (alias == library.absolutePath) return own
return privateDir(files, runCatching { File(alias).canonicalPath }.getOrDefault(alias)).takeIf { it.exists() } ?: own
}
private fun privateDir(files: File, path: String): File {
val digest = MessageDigest.getInstance("SHA-256").digest(path.toByteArray())
.joinToString("") { "%02x".format(it.toInt() and 255) }
return File(files, "steam-libraries/$digest")
}
@@ -7,6 +7,7 @@ import com.droiddeck.launcher.R
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.runtime.BattleNet
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.InstalledStoreGame
import com.droiddeck.launcher.stores.Store
@@ -130,13 +131,13 @@ object BattleNetClient {
StoresState.post { opener?.invoke(args) }
}
fun library(context: Context, root: File = preferred(context)): List<String> =
AddedGames.guestPath(context, StoreInstallRoot.storeDir(root, Store.BATTLENET))?.let { listOf("--library", it) }.orEmpty()
fun library(context: Context, root: File? = preferred(context)): List<String> =
root?.let { AddedGames.guestPath(context, StoreInstallRoot.storeDir(it, Store.BATTLENET)) }?.let { listOf("--library", it) }.orEmpty()
internal fun preferred(context: Context): File {
internal fun preferred(context: Context): File? {
val second = StoreInstallRoot.libraryRoot(context)?.absolutePath
return StoreInstallRoot.targets(context).firstOrNull { it.root.absolutePath == second && (it.root.isDirectory || it.root.mkdirs()) }?.root
?: StoreInstallRoot.internalRoot(context)
?: StoreInstallRoot.internalRoot(context).takeIf { second == null && !GameStorage.disconnected(context) }
}
fun installGame(context: Context, uid: String, root: File) {
@@ -114,6 +114,19 @@ class GameStorageTest {
assertFalse(GameStorage.disconnected(app))
}
@Test fun aRawCardPathTheProcessCannotUseFallsBackToItsStoragePath() {
val usable = setOf("/storage/A042-9B16/Games")
assertEquals("/storage/A042-9B16/Games", GameStorage.reachable("/mnt/media_rw/A042-9B16/Games") { it.path in usable })
}
@Test fun aUsableRawPathAndOtherPathsAreKept() {
assertEquals("/mnt/media_rw/A042-9B16/Games", GameStorage.reachable("/mnt/media_rw/A042-9B16/Games") { true })
assertEquals("/mnt/media_rw/0000-0000/Games", GameStorage.reachable("/mnt/media_rw/0000-0000/Games") { false })
assertEquals("/storage/A042-9B16/Games", GameStorage.reachable("/storage/A042-9B16/Games") { false })
val folder = tmp.newFolder("library").path
assertEquals(folder, GameStorage.reachable(folder) { false })
}
@Test fun onlyAVfatMountCountsAsFat32() {
val mounts = """
/dev/fuse /storage/emulated fuse rw 0 0
@@ -21,6 +21,24 @@ class SecondaryLibraryTest {
assertFalse(SecondaryLibrary.privateRoot(files, content).exists())
}
@Test fun aCardReachedThroughItsOtherPathKeepsItsPrivateDirectories() {
val files = tmp.newFolder("files")
val raw = SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/A042-9B16/Games")).apply { mkdirs() }
assertEquals(raw, SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")))
val storage = SecondaryLibrary.privateRoot(files, File("/storage/B2BD-BCFC/Games")).apply { mkdirs() }
assertEquals(storage, SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/B2BD-BCFC/Games")))
}
@Test fun aLibraryWithItsOwnPrivateDirectoriesKeepsThem() {
val files = tmp.newFolder("files")
val own = SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")).apply { mkdirs() }
val raw = File(own.parentFile, SecondaryLibrary.privateRoot(tmp.newFolder("other"), File("/mnt/media_rw/A042-9B16/Games")).name)
raw.mkdirs()
assertEquals(own, SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")))
assertEquals(raw, SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/A042-9B16/Games")))
assertFalse(SecondaryLibrary.privateRoot(files, File("/storage/emulated/0/Games")).exists())
}
@Test fun aWritableAliasIsSelectedAndItsProbeIsRemoved() {
val library = tmp.newFolder("shared")
val candidate = File(tmp.root, "direct")
@@ -0,0 +1,34 @@
package com.droiddeck.launcher.stores.battlenet
import com.droiddeck.launcher.session.SessionPrefs
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class BattleNetLibraryTest {
private val app get() = RuntimeEnvironment.getApplication()
@get:Rule val tmp = TemporaryFolder()
@Test fun aMissingLibraryLeavesBattleNetsInstallFolderAlone() {
SessionPrefs.setGameStorage(app, "/storage/0000-0000/Games", "SD card")
assertTrue(BattleNetClient.library(app).isEmpty())
}
@Test fun anAttachedLibraryIsHandedToBattleNet() {
SessionPrefs.setGameStorage(app, tmp.newFolder("card").path, "SD card")
assertEquals("--library", BattleNetClient.library(app).firstOrNull())
}
@Test fun internalStorageIsHandedToBattleNetWhenItIsTheChoice() {
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
assertEquals("--library", BattleNetClient.library(app).firstOrNull())
}
}
@@ -251,7 +251,7 @@ dd_game_cpus() {
fi
[ -n "${DD_GAME_CPUS:-}" ] || return 0
command -v taskset >/dev/null 2>&1 || return 0
DD_TASKSET="taskset -c $DD_GAME_CPUS"
DD_TASKSET=(bash -c 'taskset -cp "$1" "$$" >/dev/null 2>&1 || printf "droiddeck-proton: CPU affinity refused; using inherited cores\n" >&2; shift; exec "$@"' -- "$DD_GAME_CPUS")
echo "droiddeck-proton: game cores $DD_GAME_CPUS" >&2
}
"""
@@ -470,7 +470,7 @@ if [ -n "$depot" ]; then
DD_STORE_PROTON="$depot/proton"; export DD_STORE_PROTON
dd_store_launch "$@"
DD_STORE_ARGS=("$@")
dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
fi
echo "droiddeck-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2
exit 1
@@ -525,7 +525,7 @@ dd_libpath
DD_STORE_PROTON="$here/%s"; export DD_STORE_PROTON
dd_store_launch "$@"
DD_STORE_ARGS=("$@")
dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env "$DD_STORE_PROTON" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env "$DD_STORE_PROTON" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
"""
@@ -581,9 +581,9 @@ esac
""" + DD_DESKTOP_GPU_SETUP + DD_GAME_CPUS_SETUP + """
dd_game_cpus
if [ -x /usr/local/bin/droiddeck-steamvr-flat ] && /usr/local/bin/droiddeck-steamvr-flat "$verb"; then
exec /usr/local/bin/droiddeck-steamvr-game ${DD_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
exec /usr/local/bin/droiddeck-steamvr-game "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-fex steam "$verb" "$@"
fi
exec ${DD_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
exec "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-fex steam "$verb" "$@"
"""
+28 -9
View File
@@ -1571,15 +1571,34 @@ class AppInfoTest(unittest.TestCase):
tool, bin_dir = Path(tmp) / "droiddeck-fex", Path(tmp) / "bin"
self.COMPAT["build_fex_tool"](str(tool))
bin_dir.mkdir()
(bin_dir / "taskset").write_text('#!/bin/sh\necho "taskset $*"\n')
(bin_dir / "taskset").chmod(0o755)
env = dict(os.environ, PATH="%s:%s" % (bin_dir, os.environ.get("PATH", "")), DD_GAME_CPUS="2-7")
run = subprocess.run([str(tool / "droiddeck-fex-tool"), "waitforexitandrun", "/games/a/game"],
env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(run.stdout,
"taskset -c 2-7 /usr/local/bin/droiddeck-fex steam waitforexitandrun /games/a/game\n")
self.assertIn("game cores 2-7", run.stderr)
self.assertIn('exec /usr/local/bin/droiddeck-steamvr-game ${DD_TASKSET:-} '
real_taskset = shutil.which("taskset")
self.assertIsNotNone(real_taskset)
inherited = sorted(os.sched_getaffinity(0))
self.assertGreater(len(inherited), 1)
chosen = str(inherited[0])
(bin_dir / "taskset").symlink_to(real_taskset)
fex = bin_dir / "fex"
fex.write_text('#!' + sys.executable + '\nimport json, os, sys\nprint(json.dumps([sorted(os.sched_getaffinity(0)), sys.argv[1:]]))\nsys.exit(37)\n')
fex.chmod(0o755)
launcher = tool / "droiddeck-fex-tool"
launcher.write_text(launcher.read_text().replace("/usr/local/bin/droiddeck-fex", str(fex)))
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(PATH="%s:%s" % (bin_dir, os.environ.get("PATH", "")), DD_GAME_CPUS=chosen)
for refused in (False, True):
with self.subTest(refused=refused):
if refused:
(bin_dir / "taskset").unlink()
(bin_dir / "taskset").write_text("#!/bin/sh\nexit 1\n")
(bin_dir / "taskset").chmod(0o755)
run = subprocess.run([str(launcher), "waitforexitandrun", "/games/a game", "", "*; argument"],
env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(run.returncode, 37, run.stderr)
self.assertEqual(json.loads(run.stdout),
[inherited if refused else [inherited[0]],
["steam", "waitforexitandrun", "/games/a game", "", "*; argument"]])
self.assertIn("game cores " + chosen, run.stderr)
self.assertEqual("CPU affinity refused" in run.stderr, refused)
self.assertIn('exec /usr/local/bin/droiddeck-steamvr-game "${DD_TASKSET[@]}" '
'/usr/local/bin/droiddeck-fex steam "$verb" "$@"', self.COMPAT["FEX_LAUNCHER_SH"])
+33 -1
View File
@@ -1,7 +1,10 @@
import json
import os
from pathlib import Path
import runpy
import shutil
import subprocess
import sys
import tempfile
import unittest
@@ -27,12 +30,41 @@ class LiveGameCpusTest(unittest.TestCase):
if live is not None:
self.live.write_bytes(live.encode())
setup = COMPAT["DD_GAME_CPUS_SETUP"].replace("/root/.config/droiddeck/game-cores", str(self.live))
script = setup + '\ndd_game_cpus\necho "taskset=${DD_TASKSET:-}"\necho "cpus=${DD_GAME_CPUS-unset}"\n'
script = setup + '\ndd_game_cpus\nif (( ${#DD_TASKSET[@]} )); then echo "taskset=taskset -c ${DD_TASKSET[4]}"; else echo "taskset="; fi\necho "cpus=${DD_GAME_CPUS-unset}"\n'
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(PATH=self.path, **extra)
result = subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, check=True)
return result.stdout.splitlines()
def test_launched_program_receives_requested_or_inherited_affinity(self):
real_taskset = shutil.which("taskset")
self.assertIsNotNone(real_taskset)
inherited = sorted(os.sched_getaffinity(0))
self.assertGreater(len(inherited), 1)
chosen = str(inherited[0])
taskset = Path(self.path.split(os.pathsep)[0]) / "taskset"
probe = Path(self.temp.name) / "probe.py"
probe.write_text('import json, os, sys\nprint(json.dumps([sorted(os.sched_getaffinity(0)), sys.argv[1:]]))\nsys.exit(37)\n')
setup = COMPAT["DD_GAME_CPUS_SETUP"].replace("/root/.config/droiddeck/game-cores", str(self.live))
script = setup + '\ndd_game_cpus\n"${DD_TASKSET[@]}" "$@"\n'
for refused in (False, True):
with self.subTest(refused=refused):
taskset.unlink()
if refused:
taskset.write_text("#!/bin/sh\nexit 1\n")
taskset.chmod(0o755)
else:
taskset.symlink_to(real_taskset)
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(PATH=self.path, DD_GAME_CPUS=chosen)
result = subprocess.run(["bash", "-c", script, "--", sys.executable, str(probe),
"first argument", "", "*; second"],
env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 37, result.stderr)
self.assertEqual(json.loads(result.stdout),
[inherited if refused else [inherited[0]], ["first argument", "", "*; second"]])
self.assertEqual("CPU affinity refused" in result.stderr, refused)
def test_a_change_made_during_the_session_wins_over_the_session_value(self):
self.assertEqual(self.run_setup("6,7\n", DD_GAME_CPUS="3,4,5,6,7"),
["taskset=taskset -c 6,7", "cpus=6,7"])
+1 -1
View File
@@ -2615,7 +2615,7 @@ class GameEnvironmentTest(unittest.TestCase):
self.assertIn('dd_directaudio "$here" "$@"', COMPAT["EXTRA_WRAPPER_SH"] % "proton")
for script in (COMPAT["LAUNCHER_SH"], COMPAT["EXTRA_WRAPPER_SH"] % "proton"):
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
self.assertIn('dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', script)
self.assertIn('dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', script)
def test_both_proton_wrappers_answer_steams_driver_query_without_wine(self):
scripts = (COMPAT["launcher_sh"](), COMPAT["extra_wrapper_sh"]("proton"))
+2 -2
View File
@@ -379,8 +379,8 @@ class CloudHooks(unittest.TestCase):
def test_both_launchers_wait_for_proton_only_for_a_store_game(self):
for sh in (compat.LAUNCHER_SH, compat.EXTRA_WRAPPER_SH):
self.assertIn('dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertNotIn('exec ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertIn('dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', sh)
self.assertNotIn('exec "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', sh)
self.assertIn('[ $rc -eq 10 ] && DD_STORE_EXIT=1', compat.DD_STORE_SETUP)
self.assertIn('droiddeck-store-launch --exited --code "$rc" "${DD_STORE_ARGS[@]}"', compat.DD_STORE_SETUP)
self.assertIn('exec "$@"', compat.DD_STORE_SETUP)