Add automatic cleanup of old core files using WordPress $_old_files list#299
Add automatic cleanup of old core files using WordPress $_old_files list#299
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…ication Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
|
we also need to check that this will not cause a regression of #196 |
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…realpath calls Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
… into a single pass Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| $has_checksums = is_array( $old_checksums ) && is_array( $new_checksums ); | ||
|
|
||
| if ( ! $has_checksums ) { | ||
| WP_CLI::warning( 'Could not retrieve WordPress core checksums; skipping checksum-based cleanup. Files listed in $_old_files were still cleaned up.' ); |
There was a problem hiding this comment.
The new warning when checksums aren’t available drops the specific context that get_core_checksums() returns (e.g. Checksums not available for WordPress <version>/<locale>. or an exception message). This is a user-visible regression in diagnostic quality compared to the previous warnings.
Suggested fix: include the underlying $old_checksums/$new_checksums string(s) in the warning (and ideally indicate whether the "from" or "to" checksums failed) while still noting that $_old_files cleanup was attempted.
| WP_CLI::warning( 'Could not retrieve WordPress core checksums; skipping checksum-based cleanup. Files listed in $_old_files were still cleaned up.' ); | |
| $details = array(); | |
| if ( ! is_array( $old_checksums ) && $old_checksums ) { | |
| $old_message = is_string( $old_checksums ) ? $old_checksums : wp_json_encode( $old_checksums ); | |
| $details[] = sprintf( | |
| '"from" version (%s) checksums: %s', | |
| $version_from, | |
| $old_message | |
| ); | |
| } | |
| if ( ! is_array( $new_checksums ) && $new_checksums ) { | |
| $new_message = is_string( $new_checksums ) ? $new_checksums : wp_json_encode( $new_checksums ); | |
| $details[] = sprintf( | |
| '"to" version (%s) checksums: %s', | |
| $version_to, | |
| $new_message | |
| ); | |
| } | |
| $details_message = $details ? ' Details: ' . implode( ' | ', $details ) : ''; | |
| WP_CLI::warning( | |
| 'Could not retrieve WordPress core checksums; skipping checksum-based cleanup. Files listed in $_old_files were still cleaned up.' . $details_message | |
| ); |
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Feature: Add support for deleting old core files using WordPress $_old_files list
Problem
Currently, when checksums for the target WordPress version and locale aren't available, WP-CLI warns users to manually clean up old files. This is inconvenient and error-prone.
Solution
This PR implements automatic cleanup using WordPress core's
$_old_filesglobal array fromwp-admin/includes/update-core.php.Cleanup Order
Old files from WordPress core's
$_old_fileslist are always cleaned up first, before fetching and comparing checksums. If checksums are available, the checksum-based diff cleanup follows.Changes Made
cleanup_extra_files()-cleanup_old_files()now runs unconditionally at the startcleanup_old_files()- runs unconditionallycleanup_old_files_not_in_checksums()- now redundantget_old_files_list()- centralizes access to$_old_filesarrayremove_old_files_from_list()- single-pass helper with early exit and path validationremove_directory()- usesRecursiveIteratorIterator/RecursiveDirectoryIteratorwithCHILD_FIRSTorderingNo files found that need cleaning up→No old files were removed.No old files were removed.and the warning about checksums being unavailableTesting
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.