Skip to content

fix(update-lgsm): build updated game script in tmpdir and restore backup on failure - #5118

Merged
dgibbs64 merged 2 commits into
developfrom
fix/3060-update-script-tmpdir
Oct 31, 2026
Merged

dgibbs64 merged 2 commits into
developfrom
fix/3060-update-script-tmpdir

Conversation

@dgibbs64

@dgibbs64 dgibbs64 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Description

update-lgsm copied linuxgsm.sh over the game script and then ran six separate sed -i calls on it in rootdir. sed -i creates its temporary file in the same directory as the target, so without write access to rootdir itself the copy succeeded but every substitution failed. The game script was left with the "core" placeholders and reported unknown game server. Only the last sed exit code was checked, and the backup taken just before was never restored.

Changes:

  • The updated script is built in tmpdir with a single sed -i -e ... call, and that result is checked.
  • It is then copied over the existing game script, which only needs write access to the file, not to rootdir.
  • If that copy fails, the backup is restored.
  • The backup path is computed once, so the logged location matches the file actually written (previously date was called three times).

Fixes #3060

Affected servers: all

Type of change

  • Bug fix (a change which fixes an issue).
  • New feature (a change which adds functionality).
  • New Server (new server added).
  • Refactor (restructures existing code).
  • Chore (CI, workflows, tooling or other maintenance).
  • Comment update (typo, spelling, explanation, examples, etc).

Testing

  • Commands/tests run:
    • shellcheck -x on the module.
    • End to end: pmcserver in a throwaway container. rootdir set to root:root 755 with all contents owned by linuxgsm (the setup from the issue), and a line appended to the game script so update-lgsm always has a change to apply. Ran LGSM_GITHUBBRANCH=<branch> ./pmcserver update-lgsm on develop and on this branch (after a first run to fetch that branch's modules), then ./pmcserver details.
    • Also ran it with the game script itself read-only, so the final copy fails.
    • Unit-style: the script-update block on its own with stubbed print and log functions, with the final copy forced to fail.
  • Result:
    • develop: all six sed calls failed with couldn't open temporary file <rootdir>/sedXXXXXX: Permission denied, the script was left with shortname="core", and details reported Unknown game server. The backup was not restored.
    • This branch: copying pmcserver ... OK, the script has the correct shortname/gameservername, details works, and no temporary files are left in rootdir or tmpdir.
    • Read-only game script: the copy and the restore both fail (neither can write the file), and the original script is left untouched and still works.
    • Forced copy failure (unit-style): the backup is restored.
  • Environment used (distro/version): gameservermanagers/linuxgsm:ubuntu-26.04 container on a test server.

Risk and rollback

  • Risk level: low
  • Rollback plan: revert this commit; the backup of the game script is still written to lgsm/backup/script/ before any change.

Breaking changes

  • No breaking changes.
  • Breaking changes included (describe below).

Documentation

Checklist

PR will not be merged until all steps are complete.

  • This pull request links to an issue ("Fixes", or "Related to" for a partial fix).
  • This pull request uses the develop branch as its base.
  • This pull request subject follows the Conventional Commits standard.
  • This code follows the style guidelines of this project.
  • I have performed a self-review of my code.
  • I have provided a detailed enough description of this PR.

Thank you for your Pull Request!

…kup on failure

sed -i writes its temporary file next to the target, so editing the game
script in place needed write access to rootdir itself. Without it the
copy from linuxgsm.sh succeeded but the substitutions failed, leaving the
script with the "core" placeholders ("unknown game server"). Only the last
sed call was checked, and the backup taken just before was never restored.

The script is now assembled in tmpdir with a single sed call and copied
over the existing file, which only needs write access to the file. If
that copy fails, the backup is restored. The backup path is computed once
so the logged location matches the file actually written.

Fixes #3060
@github-actions github-actions Bot added the type: bugfix Pull request that fixes a bug label Oct 31, 2026
@dgibbs64 dgibbs64 added this to the v26.5.0 milestone Oct 31, 2026
@github-actions github-actions Bot added the engine: lwjgl2 Issues related to lwjgl2 engine label Oct 31, 2026
@dgibbs64
dgibbs64 merged commit a3b92f7 into develop Oct 31, 2026
54 checks passed
@github-actions github-actions Bot added the game: PaperMC Issues related to PaperMC label Oct 31, 2026
@dgibbs64
dgibbs64 deleted the fix/3060-update-script-tmpdir branch October 31, 2026 11:38
@dgibbs64 dgibbs64 linked an issue Nov 1, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine: lwjgl2 Issues related to lwjgl2 engine game: PaperMC Issues related to PaperMC type: bugfix Pull request that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permissions edge-case during updates

1 participant