Make WordPress Core


Ignore:
Timestamp:
11/11/2022 03:53:19 PM (20 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.