Let one process work in a launcher folder at a time, and one job on the same thing.

The window already locked data/launcher.lock, but a second one closed without a word, the command line did not take
the lock, and nothing kept two jobs apart. The lock is now launcher/locks.py: the window, every command but check and
every job that changes files hold it, the one refused says who holds it, and a job names what it changes so that a
second one on the same thing fails before its first step.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 22:06:26 -05:00
parent ec9dd522b1
commit 3ca1541e0e
7 changed files with 421 additions and 38 deletions

View File

@@ -21,7 +21,7 @@ if __name__ == '__main__' and not __package__:
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
__package__ = 'launcher' # noqa: A001 — lets the relative imports below work when run as a script
from . import build, gamefiles, jobs, versions # noqa: E402
from . import build, gamefiles, jobs, locks, versions # noqa: E402
from .context import Context # noqa: E402
from .paths import Layout # noqa: E402
@@ -65,6 +65,24 @@ def main(argv=None):
p.add_argument('old')
a = ap.parse_args(argv)
ctx = Context(Layout(root=a.root) if a.root else None, echo=False)
if a.cmd == 'check': # reads the feed and changes nothing: it runs beside an open launcher
return run(a, ctx, None)
# Every other command changes the launcher's folder or the game's, as the window's jobs do: it holds the folder's
# lock (launcher/locks.py) from before it writes the settings until it ends, and is refused while the window or
# another command holds it
try:
held = locks.FileLock(ctx.layout.instance_lock, f'"{a.cmd}" from the command line', where=ctx.layout.root)
except locks.Busy as e:
print(f'error: {e}. Close it, or wait until it is done, and try again.', file=sys.stderr, flush=True)
return 1
try:
return run(a, ctx, held)
finally:
held.release()
def run(a, ctx, held):
"""One command. held: the launcher folder's lock, which `update` lets go of before the new version takes over."""
s = ctx.settings
if a.cmd == 'check':
@@ -93,6 +111,7 @@ def main(argv=None):
new = ctx.layout.apps / versions.display(check.release.version)
cli = new / 'launcher' / 'cli.py'
print(f'finishing in {versions.display(check.release.version)}', flush=True)
held.release() # the new version's command takes the lock itself
return subprocess.call([ctx.layout.python_for_builds(), str(cli), '--root', str(ctx.layout.root),
'continue-update', ctx.version])