Skip to content

fix(transport): Re-download missing packages when zip or extracted folder is absent#16905

Open
Ibochkarev wants to merge 1 commit intomodxcms:3.xfrom
Ibochkarev:fix/package-manager-redownload-missing
Open

fix(transport): Re-download missing packages when zip or extracted folder is absent#16905
Ibochkarev wants to merge 1 commit intomodxcms:3.xfrom
Ibochkarev:fix/package-manager-redownload-missing

Conversation

@Ibochkarev
Copy link
Collaborator

@Ibochkarev Ibochkarev commented Feb 26, 2026

What does it do?

  • Re-download: When the zip file is missing, use metadata location (or file.children.location) to get the download URL and fetch the package from the provider.
  • Empty directory: Treat an empty unpacked directory as packed so the package is re-unpacked.
  • HTTP errors: For cURL and fsockopen, detect 4xx/5xx responses and avoid saving error pages (HTML/JSON) as .zip files.
  • getMetadata(): New method to convert metadata into a keyed array for easier access.
  • Referer: Use url_scheme option instead of hardcoded http:// in fsockopen requests.
  • Update mode: Skip re-download when $sourceFile already contains a URL (//).
  • Guard: Add explicit check and early return when metadata has no usable location.
  • fsockopen: Fix status line parsing (buffer size 32), add $_SERVER[SERVER_PROTOCOL] fallback for CLI.

Why is it needed?

The Package Manager could not re-download packages when the zip file or extracted folder was missing (e.g. after excluding the packages folder from backups). Re-install would fail without attempting a new download. Additionally, when the provider returned 4xx/5xx (e.g. 404 for removed packages), the error response was saved as a .zip file, causing "could not unpack package" failures.

How to test

  1. Install a package via Package Manager.
  2. Delete the corresponding .transport.zip file from core/packages/ (or remove the unpacked folder).
  3. In Package Manager, click "Re-install" on the package.
  4. Verify the package is re-downloaded and installed successfully.
  5. For HTTP error handling: use a package whose download URL returns 404 — verify no invalid .zip is saved.

Related issue(s)/PR(s)

Ports logic from PR #14018 (Re-Download missing packages by exside). Addresses review feedback from comment #3963868915.

…lder is absent

- Add re-download logic: when zip is missing, use metadata location (or
  file.children.location) to fetch the package from provider
- Treat empty unpacked directory as packed so package is re-unpacked
- Add HTTP status check for cURL: do not save 4xx/5xx responses as zip
- Add getMetadata() method to convert metadata into keyed array
- Use url_scheme option for Referer in fsockopen (instead of hardcoded http://)
- Skip re-download when sourceFile already contains URL (update mode)
- Add guard when metadata has no usable location (early return with log)
- Fix fsockopen: parse status line, return empty on 4xx/5xx, add
  SERVER_PROTOCOL fallback for CLI, use buffer size 32 for status line

Refs modxcms#14018
@Ibochkarev Ibochkarev force-pushed the fix/package-manager-redownload-missing branch from 8502f7f to 71d7fc3 Compare February 26, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant