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
This commit is contained in:
dd32 2010-02-19 10:59:32 +00:00
parent f0fc5c2dd4
commit 9d23c565bd

View File

@ -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;
}