Make WordPress Core

Changeset 54815


Ignore:
Timestamp:
11/11/2022 03:53:19 PM (13 months ago)
Author:
desrosj
Message:

Filesystem: Return FTP/FTP Sockets exists() methods to a previous state.

This partially reverts [53860] and [53862], which refactored the exists() method to rely on ftp_rawlist() instead of ftp_nlist().

[53860] makes a similar attempt to the ones made in [33648] and [34733] (which were also reverted in [35944]). Being compliant with the specifications while continuing to work without issue for all FTP servers continues seem impossible. These little ghosts are the ones we’re scared of the most.

Props jsh4, afragen, costdev, pkolenbr, SergeyBiryukov, dd32, peterwilsoncc, gamecreature, desrosj.
Fixes #56966.
See #51170, #28013.

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

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

    r53898 r54815  
    413413     *
    414414     * @since 2.5.0
    415      * @since 6.1.0 Uses WP_Filesystem_FTPext::is_dir() to check for directory existence
    416      *              and ftp_rawlist() to check for file existence.
    417415     *
    418416     * @param string $path Path to file or directory.
     
    420418     */
    421419    public function exists( $path ) {
    422         if ( $this->is_dir( $path ) ) {
    423             return true;
    424         }
    425 
    426         return ! empty( ftp_rawlist( $this->link, $path ) );
     420        $list = ftp_nlist( $this->link, $path );
     421
     422        if ( empty( $list ) && $this->is_dir( $path ) ) {
     423            return true; // File is an empty directory.
     424        }
     425
     426        return ! empty( $list ); // Empty list = no file, so invert.
    427427    }
    428428
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r53872 r54815  
    415415     *
    416416     * @since 2.5.0
    417      * @since 6.1.0 Uses WP_Filesystem_ftpsockets::is_dir() to check for directory existence
    418      *              and file size to check for file existence.
    419417     *
    420418     * @param string $path Path to file or directory.
     
    422420     */
    423421    public function exists( $path ) {
    424         if ( $this->is_dir( $path ) ) {
    425             return true;
    426         }
    427 
    428         return is_numeric( $this->size( $path ) );
     422        $list = $this->ftp->nlist( $path );
     423
     424        if ( empty( $list ) && $this->is_dir( $path ) ) {
     425            return true; // File is an empty directory.
     426        }
     427
     428        return ! empty( $list ); // Empty list = no file, so invert.
     429        // Return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server.
    429430    }
    430431
Note: See TracChangeset for help on using the changeset viewer.