-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix cli cache prune to handle version numbers in cache filenames
#6152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: swissspidy <[email protected]>
cli cache prune to handle version numbers in cache filenames
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the cli cache prune command to properly handle cache files with semantic version numbers (e.g., jetpack-8.6.1.zip). Previously, the prune logic only worked with numeric timestamps and skipped all files with dotted version numbers because is_numeric('8.6.1') returns false.
Key changes:
- Rewrote the version extraction logic to handle both numeric timestamps and semantic version strings using regex matching
- Implemented version-aware sorting using PHP's
version_compare()function with fallback to modification time - Changed from immediate deletion to a grouping-then-pruning approach for better maintainability
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| php/WP_CLI/FileCache.php | Refactored prune() method to extract and compare semantic versions using version_compare(), with mtime fallback for non-versioned files |
| features/cli-cache.feature | Added comprehensive test scenario verifying version-numbered plugin cache files are correctly pruned, keeping only the highest version |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: swissspidy <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
f68906a to
05bce81
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: schlessera <[email protected]>
Description
The
prune()method skipped cache files with version numbers (e.g.,jetpack-8.6.1.zip) becauseis_numeric('8.6.1')returns false. Files were never pruned despite reporting "Success: Cache pruned."Solution
Extract version strings, not just numeric timestamps
is_numeric()to matching/^(\d+(?:\.\d+)*)/12345and8.6.1formatsUse
version_compare()for sorting$b['version'] <=> $a['version']version_compare('8.9.1', '8.6.1')returns 1Group before pruning
Coding standards compliance
count()call outside loop condition per WP-CLI coding standardsstatic functionwhen no$thisinstance context is usedUpdated for compatibility with main branch
get_cache_files()method using native PHP iteratorsChanges
php/WP_CLI/FileCache.php: Rewrite prune logic (~50 lines) and update to use native PHP iteratorsfeatures/cli-cache.feature: Add test for version-numbered cache filesExample
Before: All plugin versions kept (no numeric timestamp to compare)
After: Highest version kept via
version_compare()Numeric timestamps still work (backward compatible):
Original prompt
cli cache prunedoesn't clear cache when file timemods are all the same #5467💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.