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.
Built from https://develop.svn.wordpress.org/trunk@54815


git-svn-id: http://core.svn.wordpress.org/trunk@54367 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2022-11-11 15:55:13 +00:00
parent 43addd9e1e
commit 4e492ffe61
3 changed files with 12 additions and 11 deletions

View File

@ -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.
}
/**

View File

@ -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.
}
/**

View File

@ -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.