From 9b79c3671320f43ca8daffe9cd20af4d642ad68e Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 18 Mar 2015 19:22:27 +0000 Subject: [PATCH] WP_Filesystem: Change `WP_Filesystem_FTPext::exists()` and `WP_Filesystem_ftpsockets::exists()` to return true for empty directories. Both methods are using *nlist() which returns a list of files in a given directory or the file itself for a given file. If the result was an empty list we assumed that the file doesn't exists. This includes also cases where $file is actually an empty directory. To prevent this we now check if $file is a directory before returning the result of an empty list. Other filesystem methods are using `file_exists()` which already checks whether a file or directory exists. fixes #30815. Built from https://develop.svn.wordpress.org/trunk@31815 git-svn-id: http://core.svn.wordpress.org/trunk@31797 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-filesystem-ftpext.php | 5 +++++ wp-admin/includes/class-wp-filesystem-ftpsockets.php | 5 +++++ wp-includes/version.php | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index 109acc16ff..f9f46e7c81 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -275,6 +275,11 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { */ public function exists($file) { $list = @ftp_nlist($this->link, $file); + + if ( empty( $list ) && $this->is_dir( $file ) ) { + return true; // File is an empty directory. + } + 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 a2b3cada88..ec85d36b7b 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -274,6 +274,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { */ public function exists( $file ) { $list = $this->ftp->nlist( $file ); + + if ( empty( $list ) && $this->is_dir( $file ) ) { + return true; // File is an empty directory. + } + 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 180fd9eb05..a56a153ffb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-beta1-31814'; +$wp_version = '4.2-beta1-31815'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.