Make app re-runs actually refresh a stale image/icon field
update_field() only ever got called for 'mounts' and 'env' when an app was already present in config.toml, so the games-on-whales/desktop -> xfce image-name fix from the previous commit would NOT have reached anyone who already has a (broken) Desktop entry — re-running the installer or ./manage.sh apps would keep refreshing mounts/env but silently leave the old, 404ing image reference in place forever. update_field's own array-reformatting logic (scan forward for a closing ']') isn't safe to reuse for a single-line scalar field like image or icon_png_path — there's no ']' on that line, so the scan would run into an unrelated array further down the same block (e.g. 'ports = []') and corrupt it. Added a separate update_scalar_field() that only ever replaces the exact matched line, and wired it in for both 'image' and 'icon_png_path' in both copies of this app-injector script (install-time and manage.sh's own 'apps' command) — verified locally against a synthetic config.toml block that it replaces only the targeted app's own fields and leaves a neighboring app's identically-named fields untouched. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLX1yYKJExGSXmgUhxKQG6
This commit is contained in:
@@ -1820,6 +1820,33 @@ def update_field(lines, wolf_name, field, new_value):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def update_scalar_field(lines, wolf_name, field, new_value):
|
||||||
|
# Same block-bounding as update_field, but for a single-line scalar
|
||||||
|
# string field (image, icon_png_path) that Wolf never reformats across
|
||||||
|
# multiple lines. update_field's array logic (which scans forward
|
||||||
|
# hunting for a closing ']') isn't safe to reuse here — a scalar line
|
||||||
|
# has no ']' of its own and that scan would run off into an unrelated
|
||||||
|
# array field further down the same block (e.g. 'ports = []'),
|
||||||
|
# corrupting it. Confirmed needed live: a stale 'image' field (e.g. the
|
||||||
|
# games-on-whales/desktop -> xfce rename) was NOT refreshed by
|
||||||
|
# update_field, since only 'mounts'/'env' were ever passed to it — an
|
||||||
|
# already-installed app's broken image reference survived every
|
||||||
|
# reinstall/'./manage.sh apps' re-run until this was added.
|
||||||
|
for i, line in enumerate(lines):
|
||||||
|
if f"name = '{wolf_name}'" in line:
|
||||||
|
block_start = i
|
||||||
|
while block_start > 0 and lines[block_start].strip() != '[[profiles.apps]]':
|
||||||
|
block_start -= 1
|
||||||
|
block_end = i + 1
|
||||||
|
while block_end < len(lines) and lines[block_end].strip() not in ('[[profiles.apps]]', '[[profiles]]'):
|
||||||
|
block_end += 1
|
||||||
|
for j in range(block_start, block_end):
|
||||||
|
if lines[j].lstrip().startswith(field + " = '"):
|
||||||
|
indent = lines[j][:len(lines[j]) - len(lines[j].lstrip())]
|
||||||
|
lines[j] = f"{indent}{field} = '{new_value}'\n"
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
with open(cfg, 'r') as f:
|
with open(cfg, 'r') as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
@@ -1846,6 +1873,8 @@ for key in list(CATALOG.keys()):
|
|||||||
if already:
|
if already:
|
||||||
ok = update_field(lines, wolf_name, 'mounts', new_mounts)
|
ok = update_field(lines, wolf_name, 'mounts', new_mounts)
|
||||||
ok = update_field(lines, wolf_name, 'env', new_env) or ok
|
ok = update_field(lines, wolf_name, 'env', new_env) or ok
|
||||||
|
ok = update_scalar_field(lines, wolf_name, 'image', app['image']) or ok
|
||||||
|
ok = update_scalar_field(lines, wolf_name, 'icon_png_path', app['icon']) or ok
|
||||||
if ok:
|
if ok:
|
||||||
updated.append(app['title'])
|
updated.append(app['title'])
|
||||||
else:
|
else:
|
||||||
@@ -3244,6 +3273,33 @@ def update_field(lines, wolf_name, field, new_value):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def update_scalar_field(lines, wolf_name, field, new_value):
|
||||||
|
# Same block-bounding as update_field, but for a single-line scalar
|
||||||
|
# string field (image, icon_png_path) that Wolf never reformats across
|
||||||
|
# multiple lines. update_field's array logic (which scans forward
|
||||||
|
# hunting for a closing ']') isn't safe to reuse here — a scalar line
|
||||||
|
# has no ']' of its own and that scan would run off into an unrelated
|
||||||
|
# array field further down the same block (e.g. 'ports = []'),
|
||||||
|
# corrupting it. Confirmed needed live: a stale 'image' field (e.g. the
|
||||||
|
# games-on-whales/desktop -> xfce rename) was NOT refreshed by
|
||||||
|
# update_field, since only 'mounts'/'env' were ever passed to it — an
|
||||||
|
# already-installed app's broken image reference survived every
|
||||||
|
# './manage.sh apps' re-run until this was added.
|
||||||
|
for i, line in enumerate(lines):
|
||||||
|
if f"name = '{wolf_name}'" in line:
|
||||||
|
block_start = i
|
||||||
|
while block_start > 0 and lines[block_start].strip() != '[[profiles.apps]]':
|
||||||
|
block_start -= 1
|
||||||
|
block_end = i + 1
|
||||||
|
while block_end < len(lines) and lines[block_end].strip() not in ('[[profiles.apps]]', '[[profiles]]'):
|
||||||
|
block_end += 1
|
||||||
|
for j in range(block_start, block_end):
|
||||||
|
if lines[j].lstrip().startswith(field + " = '"):
|
||||||
|
indent = lines[j][:len(lines[j]) - len(lines[j].lstrip())]
|
||||||
|
lines[j] = f"{indent}{field} = '{new_value}'\n"
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
with open(cfg, 'r') as f:
|
with open(cfg, 'r') as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
@@ -3273,6 +3329,8 @@ for key in list(CATALOG.keys()): # preserve display order
|
|||||||
if already:
|
if already:
|
||||||
ok = update_field(lines, wolf_name, 'mounts', new_mounts)
|
ok = update_field(lines, wolf_name, 'mounts', new_mounts)
|
||||||
ok = update_field(lines, wolf_name, 'env', new_env) or ok
|
ok = update_field(lines, wolf_name, 'env', new_env) or ok
|
||||||
|
ok = update_scalar_field(lines, wolf_name, 'image', app['image']) or ok
|
||||||
|
ok = update_scalar_field(lines, wolf_name, 'icon_png_path', app['icon']) or ok
|
||||||
if ok:
|
if ok:
|
||||||
updated.append(app['title'])
|
updated.append(app['title'])
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user