From f159af51118e7ae23ffcbcc993a7779a1c3d418d Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 13 Sep 2009 23:00:45 +0000 Subject: [PATCH] Plugin/Theme installer: Do not bail if empty destination directory exists, props dd32, fixes #10775 git-svn-id: https://develop.svn.wordpress.org/trunk@11926 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/class-wp-upgrader.php | 34 +++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index f99d362ed4..f00f5f2fe2 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -210,24 +210,26 @@ class WP_Upgrader { $destination = trailingslashit($destination) . trailingslashit(basename($source)); } - //If we're not clearing the destination folder, and something exists there allready, Bail. - if ( ! $clear_destination && $wp_filesystem->exists($remote_destination) ) { - $wp_filesystem->delete($remote_source, true); //Clear out the source files. - return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination ); - } else if ( $clear_destination ) { - //We're going to clear the destination if theres something there - $this->skin->feedback('remove_old'); - - $removed = true; - if ( $wp_filesystem->exists($remote_destination) ) + if ( $wp_filesystem->exists($remote_destination) ) { + if ( $clear_destination ) { + //We're going to clear the destination if theres something there + $this->skin->feedback('remove_old'); $removed = $wp_filesystem->delete($remote_destination, true); + $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra); - $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra); - - if ( is_wp_error($removed) ) - return $removed; - else if ( ! $removed ) - return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); + if ( is_wp_error($removed) ) + return $removed; + else if ( ! $removed ) + return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); + } else { + //If we're not clearing the destination folder and something exists there allready, Bail. + //But first check to see if there are actually any files in the folder. + $_files = $wp_filesystem->dirlist($remote_destination); + if ( ! empty($_files) ) { + $wp_filesystem->delete($remote_source, true); //Clear out the source files. + return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination ); + } + } } //Create destination if needed