From 9d23c565bdecc68e5f0d3525d0413511f8326e81 Mon Sep 17 00:00:00 2001 From: dd32 Date: Fri, 19 Feb 2010 10:59:32 +0000 Subject: [PATCH] Fallback to PclZip in the event that ZipArchive cannot handle a given archive properly. Close the Zip handle when we're done as well. Fixes #12230 git-svn-id: http://svn.automattic.com/wordpress/trunk@13221 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index b9557b1390..69cbf9c22a 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -528,10 +528,18 @@ function unzip_file($file, $to) { } } - if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) ) - return _unzip_file_ziparchive($file, $to, $needed_dirs); - else - return _unzip_file_pclzip($file, $to, $needed_dirs); + if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) ) { + $result = _unzip_file_ziparchive($file, $to, $needed_dirs); + if ( true === $result ) { + return $result; + } elseif ( is_wp_error($result) ) { + if ( 'incompatible_archive' != $result->get_error_code() ) + return $result; + } + echo "fall through to pcl"; + } + // Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file. + return _unzip_file_pclzip($file, $to, $needed_dirs); } /** @@ -591,6 +599,8 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { return new WP_Error('copy_failed', __('Could not copy file.'), $to . $file['filename']); } + $z->close(); + return true; }