wordpress-develop
wordpress-develop copied to clipboard
Check that a directory path exists before trying to recursively calculate its size.
This introduces an additional check to verify a directory exists before trying to iterate over its sizes.
Although recurse_dirsize will return a false if is_dir() returns a falsey value, it is mixed with other scenarios as well (such as permission checks and similar), by checking this against is_dir before relying on the WordPress core function, the user can be given a clear indication of why a directory has not been included in the calculation, instead of a generic one about permissions which may not be relevant for their setup.
Open to input on potential better wording for the message returned whe na directory does not exist, alternatively if we do not wish to introduce a new string at this time, the first failure scenario text could be reused, although is not 100% accurate
__( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
A new ticket should also be created to handle the scenario where a WP_Error is returned by the REST endpoint used to return filesizes, as the JavaScript does not currently know to handle this properly. I'd like to keep the two issues separate, to allow us to fix the directory existence issue as the current cause for this failing fairly consistently, and is a regression, while the lack of proper handling of errors form the endpoint has been around for a few releases now.
Trac ticket: https://core.trac.wordpress.org/ticket/61638
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.