Site Health: Correct the check for disk space available to safely perform updates.

If the available disk space exceeds the `PHP_INT_MAX` value, i.e. a 32-bit PHP version is in use with more than 2 GB free, the type casting to `(int)` could cause an overflow, and the Site Health test would then erroneously report that there is not enough free space. 

This commit removes the unnecessary type casting and uses the result from `disk_free_space()` directly.

Includes optimizing the logic to skip further checks if the available disk space could not be determined.

Follow-up to [55720].

Props mathsgrinds, Presskopp, rajinsharwar, SergeyBiryukov.
Fixes #59116.
Built from https://develop.svn.wordpress.org/trunk@56401


git-svn-id: http://core.svn.wordpress.org/trunk@55913 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-08-17 11:18:21 +00:00
parent caddf7e3dc
commit a26771b347
2 changed files with 6 additions and 14 deletions

View File

@ -1943,10 +1943,6 @@ class WP_Site_Health {
public function get_test_available_updates_disk_space() {
$available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : false;
$available_space = false !== $available_space
? (int) $available_space
: 0;
$result = array(
'label' => __( 'Disk space available to safely perform updates' ),
'status' => 'good',
@ -1963,18 +1959,14 @@ class WP_Site_Health {
'test' => 'available_updates_disk_space',
);
if ( $available_space < 100 * MB_IN_BYTES ) {
$result['description'] = __( 'Available disk space is low, less than 100 MB available.' );
if ( false === $available_space ) {
$result['description'] = __( 'Could not determine available disk space for updates.' );
$result['status'] = 'recommended';
}
if ( $available_space < 20 * MB_IN_BYTES ) {
} elseif ( $available_space < 20 * MB_IN_BYTES ) {
$result['description'] = __( 'Available disk space is critically low, less than 20 MB available. Proceed with caution, updates may fail.' );
$result['status'] = 'critical';
}
if ( ! $available_space ) {
$result['description'] = __( 'Could not determine available disk space for updates.' );
} elseif ( $available_space < 100 * MB_IN_BYTES ) {
$result['description'] = __( 'Available disk space is low, less than 100 MB available.' );
$result['status'] = 'recommended';
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-alpha-56400';
$wp_version = '6.4-alpha-56401';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.