Make WordPress Core


Ignore:
Timestamp:
08/08/2022 12:39:51 PM (2 years ago)
Author:
audrasjb
Message:

Filesystem: Rewrite FTP/FTP Sockets exists() methods to implement a more stable check.

WordPress FTP file checking was previously based upon ftp_nlist(). This function can be problematic at scale with a directory containing a large number of files. The same issue occurred using it with ftpsockets.

This changeset rewrites the FTP exists() functions to utilize a more efficient and stable check.

Props giox069, desrosj, mkox, afragen, costdev, pbiron, peterwilsoncc.
Fixes #51170.
See #53318, #39781.

File:
1 edited

Legend:

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

    r53714 r53860  
    413413     *
    414414     * @since 2.5.0
     415     * @since 6.1.0 Rewrite using ftp_rawlist, uses 'LIST' on FTP server
     416     *              takes file path or directory path as parameter.
    415417     *
    416418     * @param string $file Path to file or directory.
     
    418420     */
    419421    public function exists( $file ) {
    420         $list = ftp_nlist( $this->link, $file );
    421 
    422         if ( empty( $list ) && $this->is_dir( $file ) ) {
    423             return true; // File is an empty directory.
    424         }
    425 
    426         return ! empty( $list ); // Empty list = no file, so invert.
     422        if ( $this->is_dir( $file ) ) {
     423            return true;
     424        }
     425
     426        return ! empty( ftp_rawlist( $this->link, $file ) );
    427427    }
    428428
     
    511511     *
    512512     * @since 2.5.0
     513     * @since 6.1.0 Update for proper return values.
    513514     *
    514515     * @param string $file Path to file.
    515      * @return int|false Size of the file in bytes on success, false on failure.
     516     * @return int Size of the file in bytes on success, -1 on failure.
    516517     */
    517518    public function size( $file ) {
Note: See TracChangeset for help on using the changeset viewer.