Skip to content

Commit

Permalink
Site Health: Correct the check for disk space available to safely per…
Browse files Browse the repository at this point in the history
…form 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@56401 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Aug 17, 2023
1 parent 8cd9907 commit 3131800
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/wp-admin/includes/class-wp-site-health.php
Original file line number Diff line number Diff line change
Expand Up @@ -1943,10 +1943,6 @@ public function get_test_plugin_theme_auto_updates() {
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',
Expand All @@ -1963,18 +1959,14 @@ public function get_test_available_updates_disk_space() {
'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';
}

Expand Down

0 comments on commit 3131800

Please sign in to comment.