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-ftpsockets.php

    r52332 r53860  
    415415     *
    416416     * @since 2.5.0
     417     * @since 6.1.0 Rewrite using file size.
    417418     *
    418419     * @param string $file Path to file or directory.
     
    420421     */
    421422    public function exists( $file ) {
    422         $list = $this->ftp->nlist( $file );
    423 
    424         if ( empty( $list ) && $this->is_dir( $file ) ) {
    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.
     423        if ( $this->is_dir( $file ) ) {
     424            return true;
     425        }
     426
     427        return is_numeric( $this->size( $file ) );
    430428    }
    431429
Note: See TracChangeset for help on using the changeset viewer.