From a070a5e38f040e903268685248b61003768cd7f2 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 13 Nov 2008 18:48:54 +0000 Subject: [PATCH] Revert [9523]. fixes #8195 see #7395 git-svn-id: https://develop.svn.wordpress.org/trunk@9664 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/file.php | 56 ---------------------------- wp-admin/includes/plugin-install.php | 55 ++++++++++++++------------- wp-admin/includes/update.php | 24 +++++------- 3 files changed, 39 insertions(+), 96 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 76b14df068..a0cf49a54f 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -485,14 +485,6 @@ function unzip_file($file, $to) { if ( 0 == count($archive_files) ) return new WP_Error('empty_archive', __('Empty archive')); - //Prepend another directory level if there are files in the root directory of the zip - foreach ( $archive_files as $archive_file ) { - if ( false === strpos($archive_file['filename'], '/') ) { - $to = trailingslashit($to) . basename($file, '.zip'); - break; - } - } - $path = explode('/', untrailingslashit($to)); for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/' $tmppath = implode('/', array_slice($path, 0, $i) ); @@ -572,54 +564,6 @@ function copy_dir($from, $to) { } } -/** - * Locates the lowest safe directory in a Plugin folder to copy to the plugins directory. - * - * Note: Desination directory will allways be unique. - * - * @since 2.7.0 - * - * @param string $from the Working directory of the plugin files - * @param string $to the proposed destination for the for the plugin files - * @return array an array of the keys 'from' and 'to' for the actual copy. - */ -function update_pluginfiles_base_dir($from, $to) { - $files = list_files($from); - - //Remove non-php files - foreach ( (array)$files as $key => $file ) - if ( ! preg_match('!.php$!i', $file) ) - unset($files[$key]); - - //remove non-plugin files - foreach ( (array)$files as $key => $file ) { - $details = get_plugin_data($file, false, false); - if ( empty($details['Name']) ) - unset($files[$key]); - } - - if ( empty($files) ) - return false; - - //Left with paths to files which ARE plugins. - $min_num = 100; //assume no zips with deeper paths will come along - $min_file = ''; - foreach ( (array)$files as $key => $file ) { - $this_num = substr_count($file, '/'); - if ( $this_num < $min_num ) { - $min_file = $file; - $min_num = $this_num; - } - } - unset($min_num); - - $from = dirname($min_file); - //Ensure its a unique install folder, Upgrades delete the folder prior to this. - $to = dirname($to) . '/' . wp_unique_filename(dirname($to), basename($to)); - - return compact('from', 'to'); -} - /** * {@internal Missing Short Description}} * diff --git a/wp-admin/includes/plugin-install.php b/wp-admin/includes/plugin-install.php index efd156b225..ec27b471a7 100644 --- a/wp-admin/includes/plugin-install.php +++ b/wp-admin/includes/plugin-install.php @@ -744,34 +744,37 @@ function wp_install_plugin($package, $feedback = '') { return $result; } - apply_filters('install_feedback', __('Installing the plugin')); - + //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); - //find base plugin directory - $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]); - - //Create folder if not exists. - if( ! $wp_filesystem->exists( $res['to'] ) ) - if ( ! $wp_filesystem->mkdir( $res['to'], 0755 ) ) - return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); + if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) { + $wp_filesystem->delete($working_dir, true); + return new WP_Error('install_folder_exists', __('Folder allready exists.'), $filelist[0] ); + } + apply_filters('install_feedback', __('Installing the plugin')); // Copy new version of plugin into place. - $result = copy_dir($res['from'], $res['to']); + $result = copy_dir($working_dir, $plugins_dir); if ( is_wp_error($result) ) { $wp_filesystem->delete($working_dir, true); return $result; } + //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin + $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); + // Remove working directory $wp_filesystem->delete($working_dir, true); - $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); + if( empty($filelist) ) + return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. + + $folder = $filelist[0]; $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list //Return the plugin files name. - return $folder . $pluginfiles[0]; + return $folder . '/' . $pluginfiles[0]; } /** @@ -836,35 +839,37 @@ function wp_install_plugin_local_package($package, $feedback = '') { return $result; } - apply_filters('install_feedback', __('Installing the plugin')); - + //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); - //find base plugin directory - $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]); - - //Create folder if not exists. - if( ! $wp_filesystem->exists( $res['to'] ) ) { - if ( ! $wp_filesystem->mkdir( $res['to'], 0755 ) ) - return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); + if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) { + $wp_filesystem->delete($working_dir, true); + return new WP_Error('install_folder_exists', __('Folder allready exists.'), $filelist[0] ); } - + + apply_filters('install_feedback', __('Installing the plugin')); // Copy new version of plugin into place. - $result = copy_dir($res['from'], $res['to']); + $result = copy_dir($working_dir, $plugins_dir); if ( is_wp_error($result) ) { $wp_filesystem->delete($working_dir, true); return $result; } + //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin + $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); + // Remove working directory $wp_filesystem->delete($working_dir, true); - $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); + if( empty($filelist) ) + return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. + + $folder = $filelist[0]; $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list //Return the plugin files name. - return $folder . $pluginfiles[0]; + return $folder . '/' . $pluginfiles[0]; } ?> diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php index 2dd11f4f4c..ee155bb97e 100644 --- a/wp-admin/includes/update.php +++ b/wp-admin/includes/update.php @@ -246,36 +246,30 @@ function wp_update_plugin($plugin, $feedback = '') { } apply_filters('update_feedback', __('Installing the latest version')); - - $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); - - //find base plugin directory - $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]); - - //Create folder if not exists. - if( ! $wp_filesystem->exists( $res['to'] ) ) - if ( ! $wp_filesystem->mkdir( $res['to'], 0755 ) ) - return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); - // Copy new version of plugin into place. - $result = copy_dir($res['from'], $res['to']); + $result = copy_dir($working_dir, $plugins_dir); if ( is_wp_error($result) ) { $wp_filesystem->delete($working_dir, true); return $result; } + //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin + $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); + // Remove working directory $wp_filesystem->delete($working_dir, true); // Force refresh of plugin update information delete_option('update_plugins'); - $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); + if( empty($filelist) ) + return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. + + $folder = $filelist[0]; $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list - //Return the plugin files name. - return $folder . $pluginfiles[0]; + return $folder . '/' . $pluginfiles[0]; } function wp_update_theme($theme, $feedback = '') {