From e9da1dc1f221a74f54dce96079219343a8903243 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 18 Mar 2015 19:21:33 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@31815 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-filesystem-ftpext.php | 5 +++++ src/wp-admin/includes/class-wp-filesystem-ftpsockets.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpext.php b/src/wp-admin/includes/class-wp-filesystem-ftpext.php index 109acc16ff..f9f46e7c81 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/src/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/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php index a2b3cada88..ec85d36b7b 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/src/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. }