From 61ddb267ba870ac5affab994c1b2ace9c76aab14 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Fri, 11 Nov 2022 15:53:19 +0000 Subject: [PATCH] Filesystem: Return FTP/FTP Sockets `exists()` methods to a previous state. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. git-svn-id: https://develop.svn.wordpress.org/trunk@54815 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-filesystem-ftpext.php | 10 +++++----- .../includes/class-wp-filesystem-ftpsockets.php | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpext.php b/src/wp-admin/includes/class-wp-filesystem-ftpext.php index c3bb635809..296a5d2970 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -412,18 +412,18 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { * Checks if a file or directory exists. * * @since 2.5.0 - * @since 6.1.0 Uses WP_Filesystem_FTPext::is_dir() to check for directory existence - * and ftp_rawlist() to check for file existence. * * @param string $path Path to file or directory. * @return bool Whether $path exists or not. */ public function exists( $path ) { - if ( $this->is_dir( $path ) ) { - return true; + $list = ftp_nlist( $this->link, $path ); + + if ( empty( $list ) && $this->is_dir( $path ) ) { + return true; // File is an empty directory. } - return ! empty( ftp_rawlist( $this->link, $path ) ); + return ! empty( $list ); // Empty list = no file, so invert. } /** diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php index f88166c209..192abc5ec4 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -414,18 +414,19 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { * Checks if a file or directory exists. * * @since 2.5.0 - * @since 6.1.0 Uses WP_Filesystem_ftpsockets::is_dir() to check for directory existence - * and file size to check for file existence. * * @param string $path Path to file or directory. * @return bool Whether $path exists or not. */ public function exists( $path ) { - if ( $this->is_dir( $path ) ) { - return true; + $list = $this->ftp->nlist( $path ); + + if ( empty( $list ) && $this->is_dir( $path ) ) { + return true; // File is an empty directory. } - return is_numeric( $this->size( $path ) ); + return ! empty( $list ); // Empty list = no file, so invert. + // Return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server. } /**