Skip to content

fix(core): propagate archive extraction and copy failures - #5109

Open
guilherme-praca wants to merge 1 commit into
GameServerManagers:developfrom
guilherme-praca:fix/extract-failure-propagation
Open

guilherme-praca wants to merge 1 commit into
GameServerManagers:developfrom
guilherme-praca:fix/extract-failure-propagation

Conversation

@guilherme-praca

Copy link
Copy Markdown

Description

fn_dl_extract could print "OK" and return 0 without extracting anything:

  • An unsupported MIME type matched none of the branches, so the if returned 0.
  • In selective ZIP extraction (extractsrc set) the captured status came from rm -rf, hiding failures from unzip (e.g. extractsrc not in the archive) and from cp.

Changes:

  • Add an else branch that fails with Unsupported archive type: <mime>.
  • Chain unzip && cp inside the captured command, so either failure sets the exit code.
  • Remove the temp directory only after exitcode is captured, so cleanup cannot mask a failure.
  • Capture stderr (2>&1) of tar/unzip/cp, so the reason ends up in extractcmd and the script log instead of only on the terminal.
  • Update the function header comment (it did not mention xz).

Fixes #5048

Affected servers: all servers that download archives through fn_dl_extract (install, update and fix modules, e.g. ts3, mta, fctr, xnt, jk2, steamcmd bootstrap).

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: sourced fn_dl_extract from develop and from this branch with stubbed print/log/exit functions and ran both against the same fixtures (tar.gz, tar.bz2, tar.xz, zip; truncated tar.xz and zip; plain text file; missing extractsrc for zip and tar.gz; read-only destination for selective zip). shellcheck -S warning lgsm/modules/core_dl.sh is clean.
  • Result:
case develop this PR
valid tar.gz / tar.bz2 / tar.xz / zip, full and selective OK, rc 0 OK, rc 0
truncated tar.xz / zip FAIL, rc 2 / 9 FAIL, rc 2 / 9 (error now in log)
unsupported type (text/plain) OK, rc 0, nothing extracted FAIL, rc 1
selective zip, extractsrc missing OK, rc 0 FAIL, rc 11
selective zip, cp fails OK, rc 0 FAIL, rc 1
selective tar.gz, extractsrc missing FAIL, rc 2 FAIL, rc 2

Temp directory is removed in every case. Also checked: a downloaded HTML error page (text/html) and a plain .tar now fail as unsupported.

  • Callers: every caller passes .tar.gz, .tar.bz2, .tar.xz or .zip (install_server_files, fix_, core_steamcmd, update_, and all 55 entries in mods_list.sh), so none relied on the old silent success. file is a required dependency in every distro CSV.

Failure propagation and exitbypass

  • Update path: fn_update_apply runs download and extraction in a subshell with exitbypass unset (command_update.sh), so a failed extraction stops the update.
  • Not changed here: when exitbypass is set, core_exit.sh returns instead of exiting, so the caller keeps going. One reachable case is command_update.sh → exitbypass=1 command_start.sh → check_steamcmd.sh → fn_install_steamcmd, which would continue to chmod +x steamcmd.sh after a failed extraction. This is the same for every core_exit.sh call in core_dl.sh, and a return 1 alone would not help because the callers do not check the return status, so I left it out of this PR. Happy to follow up if you want a specific approach.
  • Environment used (distro/version): Fedora 44, bash 5, GNU tar, unzip 6.0

Risk and rollback

  • Risk level: low. Successful extractions behave the same; only paths that already failed silently now stop with an error. One intended change: in selective ZIP extraction (jk2, xnt) an unzip warning (exit 1) now fails, as it already did for full ZIP extraction. On success, tar/unzip warnings are no longer printed live.
  • Rollback plan: revert this commit.

Breaking changes

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

Documentation

Checklist

  • 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.

fn_dl_extract could report success when nothing was extracted:
- an unsupported MIME type matched no branch and the if returned 0
- in selective ZIP extraction the status came from rm, hiding unzip
  and cp failures

Fail explicitly on unsupported archive types, chain unzip and cp so
either failure is reported, clean up the temp directory only after
capturing the exit code, and capture stderr so the failure reason is
written to the log.
@github-actions github-actions Bot added the type: bugfix Pull request that fixes a bug label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bugfix Pull request that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant