dxw-wordpress-plugins / mirror-wordpress-plugins

Mirrors WordPress.org plugins to GitHub as versioned repos for use by Whippet
1 stars 0 forks source link

Be more defensive about extracting zipfiles #50

Closed snim2 closed 2 months ago

snim2 commented 2 months ago

In Incident 201 we found that the Two-Factor plugin did not mirror correctly. We could not reproduce the error, but noted that had it been caused by a corrupted .zip file, we would not have caught the error. This commit corrects that by catching errors on unzipping archive files and adding the error to the failure list at the end of the log, e.g.:

==> Failed to update the following 1 plugin(s):
*** Two-Factor failed to update with message:
Zip end of central directory signature not found

This PR also adds a little more text to the logs and one more explicit rescue (which will be harder to test).

Testing

  1. Follow the instructions in the README about dry-running the code. You may want to comment out lines 137-139 in this branch (to avoid deleting files). Do this once to get at least one .zip file downloaded
  2. Corrupt the .zip file with something like truncate -s 50k Two-Factor-v0.9.1.zip
  3. Comment out the line of code that downloads the .zip file (line 109 in this branch) and the line that clones the repo (or just delete your local clone)
  4. Re-run the script and check that you get an error in the logs like the one above