Skip to content

Remove a rejected download instead of keeping it as the archive - #12

Open
nu11waredev wants to merge 1 commit into
XcodesOrg:mainfrom
nu11waredev:remove-unauthorized-download
Open

nu11waredev wants to merge 1 commit into
XcodesOrg:mainfrom
nu11waredev:remove-unauthorized-download

Conversation

@nu11waredev

Copy link
Copy Markdown

Refs XcodesOrg/xcodes#484.

Problem

When Apple redirects an Xcode or runtime download to developer.apple.com/unauthorized/, the unauthorized error is reported, but the page has already been saved at the archive's path. The next run finds that file and uses it as the archive: xcodes download prints "Found existing archive" and moves the page to Downloads, as in the report.

Cause

  • URLSession: downloadTask(with:to:resumingWith:) moves the response body to the save location, then ArchiveDownloadService validates the response and throws, leaving the file in place.
  • aria2: aria2c follows the redirect, writes the page to --out and exits 0. Aria2DownloadService returns the unauthorized error from its success handler, again leaving the file.

Fix

Remove the saved file when the download is rejected, in both paths. The fix is here rather than in the CLI (as in the closed xcodes#487) because the CLI and Xcodes.app share these services.

Testing

  • testArchiveDownloadServiceURLSessionRemovesRejectedDownload: an unauthorized response from the URLSession download removes the saved file.
  • testAria2DownloadServiceRemovesRejectedDownload: a stand-in aria2c script writes a page to --out and logs the redirect; the file is gone afterwards.
  • Both fail on main and pass with the fix. swift test: 202 tests, 0 failures.

A plain 403 or 404 without the redirect still passes validateDeveloperDownloadResponse, since it only checks the URL's path. That's a separate change to the validator.

When Apple redirects a download to its unauthorized page, both
downloaders have already saved that page at the archive's path. The
error is reported, but the next run finds the file and uses it as the
archive (XcodesOrg/xcodes#484). Remove it when the download is rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nu11waredev
nu11waredev marked this pull request as ready for review December 3, 2026 03:57
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