fix: a Steam target whose file is gone goes back to the app's exe (#2411)

* fix: a Steam target whose file is gone goes back to the app's exe

A shortcut Target edited in Steam is kept across the client's restart on
purpose, but it was kept even after the file it names disappeared. When the
app's own exe already equalled the recorded proposal, nothing replaced the dead
target: Steam started `System/launcher.exe`, Wine answered
`err:steam:run_process Failed to create process ...: 2`, and the game never ran
(#694, after #1644 and #2022 removed the two real causes).

The merge now treats a target that is not a file as no edit at all and writes
the listing's exe and StartIn. The check runs in the guest, where the shortcut's
paths live.

Fixes #694

* fix: keep a Steam target whose card is not mounted

- The app recreates /mnt/droiddeck-sd and /mnt/bannerlator-sd before binding the card, so the
  mountpoint outlives a removed card. A target directly under one had an existing parent, so
  the missing-file repair overwrote the edited Exe and Start In and kept them overwritten.
- The repair now needs the target's storage to be there: a card mountpoint that lists nothing
  is a card that is not in the device, and the edit is kept for when it returns. Extra Steam
  libraries under /mnt/droiddeck-lib/<id> get the same check.
- test_a_steam_target_under_a_bare_card_mountpoint_is_kept fails without the check and asserts
  both fields; test_a_steam_target_under_a_mounted_card_goes_back_to_the_apps keeps the repair.

* fix: repair a Steam target removed with its folder

- A missing target is gone when its storage is mounted and either its folder is still
  there or it lives in a tree the app always has (internal store installs, the internal
  Steam library). An update that removes the whole game folder now repairs the shortcut.
- Store volumes and added game folders are removable mounts too: /mnt/droiddeck-stores/<id>
  and /root/Games/<name> are checked for content before a target under them is treated as
  gone, so an unplugged volume keeps the edited Exe and Start In.
- Tests: internal folder removed repairs both fields; a bare store mountpoint and a card
  mountpoint keep both; a mounted card still repairs. 84 tests pass.

* fix: classify a Steam target by its resolved path

- A target such as /root/Games/Stores/../../../mnt/droiddeck-sd/Other.exe matched the
  internal prefix and was repaired while the card was out. internal_target and
  removable_mount now normalize the path before choosing the storage class, so the
  decision follows the file the target resolves to; the kept text is unchanged.
- test_a_steam_target_is_classified_by_its_resolved_path fails before the normalization
  (the edit is replaced) and keeps both fields after it. 85 tests pass.
This commit is contained in:
Moroni Granja authored and GitHub committed 2026-11-24 16:17:04 -05:00
1 parent ab023667a0
commit 2a51b044c5
3 files changed
+160 -3

No files matched your search

@@ -125,6 +125,14 @@ RECORD = ".droiddeck-shortcuts.json"
AWAY_LIMIT = 256
FIELDS = ("AppName", "Exe", "StartDir", "icon", "LaunchOptions")
FOLLOWED = ("StartDir", "LaunchOptions")
# Guest mountpoints whose contents live on storage the user can unplug. The app creates
# the mountpoint before binding it, so it outlives a removed card; libraries, store
# volumes and added game folders get one mountpoint each under these families.
REMOVABLE_ROOTS = ("/mnt/droiddeck-sd", "/mnt/bannerlator-sd")
REMOVABLE_FAMILIES = ("/mnt/droiddeck-lib", "/mnt/droiddeck-stores", "/root/Games")
# Guest trees the app always has, whatever storage is in the device. A target that is
# missing from one of these is gone even when its whole folder was removed.
INTERNAL_ROOTS = ("/root/Games/Stores", "/root/.local/share/Steam")
def unquoted(value):
@@ -146,6 +154,46 @@ def read_record(path):
}
def under(path, root):
return path == root or path.startswith(root + "/")
def internal_target(target):
path = os.path.normpath(target)
return any(under(path, root) for root in INTERNAL_ROOTS)
def removable_mount(target):
"""The guest mountpoint holding target, when it is storage the user can unplug."""
path = os.path.normpath(target)
for root in REMOVABLE_ROOTS:
if under(path, root):
return root
for family in REMOVABLE_FAMILIES:
prefix = family + "/"
if path.startswith(prefix):
return prefix + path[len(prefix):].split("/", 1)[0]
return None
def storage_mounted(target):
"""Whether the storage holding target is there this session.
The app creates a guest mountpoint before binding storage to it, so a mountpoint that
lists nothing is one a removed card or volume left behind. A target under it may work
again when that storage returns, so its absence is not proof the file is gone.
"""
if internal_target(target):
return True
mount = removable_mount(target)
if mount is None:
return True
try:
return bool(os.listdir(mount))
except OSError:
return False
def merge(fresh, current, state, seen):
state = state if isinstance(state, dict) else {}
rev = state.get("rev") if isinstance(state.get("rev"), int) else 0
@@ -158,7 +206,16 @@ def merge(fresh, current, state, seen):
entry = dict(current)
entry["appid"] = fresh["appid"]
exe = unquoted(fresh["Exe"])
if exe != unquoted(current.get("Exe")) and (exe != unquoted(base.get("Exe")) or seen == rev):
target = unquoted(current.get("Exe"))
# A target Steam still points at after the file is gone starts nothing, so it is not
# an edit to keep: the app's own exe replaces it (#694: a hand-typed Target outlived
# the game update that removed the file, and every launch died before the game ran).
# Only when its storage is mounted and it is missing from a tree the app always has or
# from a folder that is still there. An absent folder under a mountpoint can equally be
# unplugged storage, and that target may work again next session.
gone = (bool(target) and not os.path.isfile(target) and storage_mounted(target) and
(internal_target(target) or os.path.isdir(os.path.dirname(target))))
if exe != target and (gone or exe != unquoted(base.get("Exe")) or seen == rev):
entry["Exe"], entry["StartDir"] = fresh["Exe"], fresh["StartDir"]
for field in ("AppName", "icon"):
if current.get(field) == base.get(field):