Make WordPress Core


Ignore:
Timestamp:
08/16/2022 01:39:58 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Make WP_Filesystem_FTPext::size() return false on failure.

While WP_Filesystem_Base::size() is documented to return false on failure, ftp_size() returns -1, and the method documentation was recently updated to reflect that.

This commit restores the previous @return tag and corrects the actual return value instead, to bring consistency with all the other WP_Filesystem_*::size() methods:

  • WP_Filesystem_Base::size()
  • WP_Filesystem_Direct::size()
  • WP_Filesystem_ftpsockets::size()
  • WP_Filesystem_SSH2::size()
    @return int|false Size of the file in bytes on success, false on failure.
    

This better matches the purpose of the API to provide a consistent interface for various filesystem implementations.

Follow-up to [6779], [30678], [45226], [53860], [53862].

Fixes #51170.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php

    r53872 r53898  
    511511     *
    512512     * @since 2.5.0
    513      * @since 6.1.0 Corrected the return value: while WP_Filesystem_Base::size()
    514      *              is documented to return false on failure, ftp_size() returns -1.
    515513     *
    516514     * @param string $file Path to file.
    517      * @return int Size of the file in bytes on success, -1 on failure.
     515     * @return int|false Size of the file in bytes on success, false on failure.
    518516     */
    519517    public function size( $file ) {
    520         return ftp_size( $this->link, $file );
     518        $size = ftp_size( $this->link, $file );
     519
     520        return ( $size > -1 ) ? $size : false;
    521521    }
    522522
Note: See TracChangeset for help on using the changeset viewer.