From 041a9256fbba180f2d6e5d8bfb3c9db112b18819 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 8 Aug 2022 17:12:59 +0000 Subject: [PATCH] Docs: Improve `@since` notes for some `WP_Filesystem_*` methods: * `WP_Filesystem_FTPext::exists()` * `WP_Filesystem_FTPext::size()` * `WP_Filesystem_ftpsockets::exists()` The `::exists()` methods were previously using the FTP `NLST` command, which works for directories, but is not intended to be applied to a file. This only worked most of the time due to many FTP servers being permissive and allowing to execute `NLST` on files, which cannot be guaranteed and appears to not be the case in newer versions of Pure-FTPd (1.0.48 or later). With a recent change in [53860], both methods were updated for compatibility with RFC 959: * Both methods check if the path is a directory that can be changed into (and therefore exists). * `WP_Filesystem_FTPext` uses `ftp_rawlist()` (FTP `LIST` command) to check for file existence. * `WP_Filesystem_ftpsockets` uses file size to check for file existence. Reference: [https://www.ietf.org/rfc/rfc959.txt RFC 959: File Transfer Protocol (FTP)] Follow-up to [6779], [11821], [25274], [33648], [34733], [35944], [35946], [53860]. See #51170. git-svn-id: https://develop.svn.wordpress.org/trunk@53862 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-filesystem-ftpext.php | 7 ++++--- src/wp-admin/includes/class-wp-filesystem-ftpsockets.php | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpext.php b/src/wp-admin/includes/class-wp-filesystem-ftpext.php index fc50aaf0ef..92fb5d6bb4 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -412,8 +412,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { * Checks if a file or directory exists. * * @since 2.5.0 - * @since 6.1.0 Rewrite using ftp_rawlist, uses 'LIST' on FTP server - * takes file path or directory path as parameter. + * @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 $file Path to file or directory. * @return bool Whether $file exists or not. @@ -510,7 +510,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { * Gets the file size (in bytes). * * @since 2.5.0 - * @since 6.1.0 Update for proper return values. + * @since 6.1.0 Corrected the return value: while WP_Filesystem_Base::size() + * is documented to return false on failure, ftp_size() returns -1. * * @param string $file Path to file. * @return int Size of the file in bytes on success, -1 on failure. diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php index d0fc128a1b..cb92656aad 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -414,7 +414,8 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { * Checks if a file or directory exists. * * @since 2.5.0 - * @since 6.1.0 Rewrite using file size. + * @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 $file Path to file or directory. * @return bool Whether $file exists or not.