Make WordPress Core

Opened 6 months ago

Closed 4 months ago

Last modified 4 months ago

#61602 closed defect (bug) (fixed)

site health - disk_free_space return error

Reported by: wbdv's profile wbdv Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.7 Priority: normal
Severity: minor Version: 6.5.5
Component: Site Health Keywords: has-patch
Focuses: Cc:

Description

disk_free_space return error if there is no directory WP_CONTENT_DIR . '/upgrade/' (and by default, there is no wp-contents/upgrade directory)

Function return false and site health give an error about disk space.

Solution is simple, try to create directory WP_CONTENT_DIR.'/upgrade/' before disk_free_space.

Change History (6)

#1 @mi5t4n
6 months ago

I tested this but could not replicate the issue. The disk_free_space function is suppressed and returns false on failure.

<?php
File: src\wp-admin\includes\class-wp-site-health.php
1820:           $available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : false;

If you could tell us what is your environment like PHP version and WP version, that will help use replicate the issue.

Last edited 6 months ago by mi5t4n (previous) (diff)

#2 @wbdv
6 months ago

As you said, if wp-content/upgrade/ directory does not exists, disk_free_space() will return false. But this false means an error message in site health section of WordPress:

file: wp-admin/includes/class-wp-site-health.php
line: 1952
<?php
               if ( false === $available_space ) {
                        $result['description'] = __( 'Could not determine available disk space for updates.' );
                        $result['status']      = 'recommended';

To avoid this message, first try to create the wp-content/upgrade/ then check the disk free space. By default, wp-content/upgrade/ does not exists in wordpress (latest) and it needs to be created.

file: wp-admin/includes/class-wp-site-health.php
line: 1933
<?php
        public function get_test_available_updates_disk_space() {
+               global $wp_filesystem;
+               $wp_filesystem->mkdir( WP_CONTENT_DIR . '/upgrade/', FS_CHMOD_DIR );
                $available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : false;

This ticket was mentioned in PR #7006 on WordPress/wordpress-develop by @khokansardar.


6 months ago
#3

  • Keywords has-patch added

#4 @SergeyBiryukov
4 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 58913:

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

The wp-content/upgrade directory does not exist initially after installation, so the Site Health check could not determine the available disk space until the directory was subsequently created during an update.

By testing WP_CONTENT_DIR instead, the check can complete successfully.

This also brings consistency with similar checks in _unzip_file_ziparchive() and _unzip_file_pclzip().

Follow-up to [55720], [56401].

Props wbdv, khokansardar, mi5t4n, SergeyBiryukov.
Fixes #61602.

#5 @SergeyBiryukov
4 months ago

  • Milestone changed from Awaiting Review to 6.7

@SergeyBiryukov commented on PR #7006:


4 months ago
#6

Thanks for the PR! Merged a slightly different approach in r58913.

Note: See TracTickets for help on using tickets.