Plugin/Theme installer: Do not bail if empty destination directory exists, props dd32, fixes #10775

git-svn-id: http://svn.automattic.com/wordpress/trunk@11926 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-09-13 23:00:45 +00:00
parent dbc8095e53
commit 3d8c41869d
1 changed files with 18 additions and 16 deletions

View File

@ -210,24 +210,26 @@ class WP_Upgrader {
$destination = trailingslashit($destination) . trailingslashit(basename($source)); $destination = trailingslashit($destination) . trailingslashit(basename($source));
} }
//If we're not clearing the destination folder, and something exists there allready, Bail. if ( $wp_filesystem->exists($remote_destination) ) {
if ( ! $clear_destination && $wp_filesystem->exists($remote_destination) ) { if ( $clear_destination ) {
$wp_filesystem->delete($remote_source, true); //Clear out the source files. //We're going to clear the destination if theres something there
return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination ); $this->skin->feedback('remove_old');
} 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) )
$removed = $wp_filesystem->delete($remote_destination, true); $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;
if ( is_wp_error($removed) ) else if ( ! $removed )
return $removed; return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
else if ( ! $removed ) } else {
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); //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 //Create destination if needed