From 4e492ffe614ece2b8330a52a49dc968e5bf160e8 Mon Sep 17 00:00:00 2001 From: desrosj Date: Fri, 11 Nov 2022 15:55:13 +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. Built from https://develop.svn.wordpress.org/trunk@54815 git-svn-id: http://core.svn.wordpress.org/trunk@54367 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-filesystem-ftpext.php | 10 +++++----- wp-admin/includes/class-wp-filesystem-ftpsockets.php | 11 ++++++----- wp-includes/version.php | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index c3bb635809..296a5d2970 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/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/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index f88166c209..192abc5ec4 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/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. } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 3bb0ae220e..e913c9792d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-54813'; +$wp_version = '6.2-alpha-54815'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.