mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Upgrader: Perform a MD5 file verification check on the files during upgrade. This ensures that both a Partial upgrade build can be used, and that all the files were copied into place correctly.
Props pento for initial patch. Fixes #18201 git-svn-id: https://develop.svn.wordpress.org/trunk@25540 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -688,16 +688,62 @@ function update_core($from, $to) {
|
||||
elseif ( !$mysql_compat )
|
||||
return new WP_Error( 'mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version ) );
|
||||
|
||||
apply_filters('update_feedback', __('Installing the latest version…'));
|
||||
apply_filters( 'update_feedback', __( 'Preparing to install the latest version…' ) );
|
||||
|
||||
// Don't copy wp-content, we'll deal with that below
|
||||
$skip = array( 'wp-content' );
|
||||
|
||||
// Check to see which files don't really need updating - only available for 3.7 and higher
|
||||
if ( function_exists( 'get_core_checksums' ) ) {
|
||||
$checksums = get_core_checksums( $wp_version );
|
||||
if ( ! empty( $checksums[ $wp_version ] ) && is_array( $checksums[ $wp_version ] ) ) {
|
||||
foreach( $checksums[ $wp_version ] as $file => $checksum ) {
|
||||
if ( md5_file( ABSPATH . $file ) === $checksum )
|
||||
$skip[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
apply_filters( 'update_feedback', __( 'Enabling Maintenance mode…' ) );
|
||||
// Create maintenance file to signal that we are upgrading
|
||||
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
|
||||
$maintenance_file = $to . '.maintenance';
|
||||
$wp_filesystem->delete($maintenance_file);
|
||||
$wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
|
||||
|
||||
apply_filters( 'update_feedback', __( 'Copying the required files…' ) );
|
||||
// Copy new versions of WP files into place.
|
||||
$result = _copy_dir($from . $distro, $to, array('wp-content') );
|
||||
$result = _copy_dir( $from . $distro, $to, $skip );
|
||||
|
||||
// Check to make sure everything copied correctly, ignoring the contents of wp-content
|
||||
$skip = array( 'wp-content' );
|
||||
$failed = array();
|
||||
if ( ! empty( $checksums[ $wp_version ] ) && is_array( $checksums[ $wp_version ] ) ) {
|
||||
foreach ( $checksums[ $wp_version ] as $file => $checksum ) {
|
||||
if ( 0 === strpos( $file, 'wp-content' ) )
|
||||
continue;
|
||||
|
||||
if ( md5_file( ABSPATH . $file ) == $checksum )
|
||||
$skip[] = $file;
|
||||
else
|
||||
$failed[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Some files didn't copy properly
|
||||
if ( ! empty( $failed ) ) {
|
||||
$total_size = 0;
|
||||
// Find the local version of the working directory
|
||||
$working_dir_local = str_replace( trailingslashit( $wp_filesystem->wp_content_dir() ), trailingslashit( WP_CONTENT_DIR ), $from . $distro );
|
||||
foreach ( $failed as $file )
|
||||
$total_size += filesize( $working_dir_local . '/' . $file );
|
||||
|
||||
// If we don't have enough free space, it isn't worth trying again
|
||||
if ( $total_size >= disk_free_space( ABSPATH ) )
|
||||
$result = new WP_Error( 'disk_full', __( "There isn't enough free disk space to complete the upgrade." ), $to );
|
||||
else
|
||||
$result = _copy_dir( $from . $distro, $to, $skip );
|
||||
}
|
||||
|
||||
// Custom Content Directory needs updating now.
|
||||
// Copy Languages
|
||||
@@ -795,6 +841,7 @@ function update_core($from, $to) {
|
||||
else
|
||||
delete_option('update_core');
|
||||
|
||||
apply_filters( 'update_feedback', __( 'Disabling Maintenance mode…' ) );
|
||||
// Remove maintenance file, we're done.
|
||||
$wp_filesystem->delete($maintenance_file);
|
||||
|
||||
@@ -808,10 +855,12 @@ function update_core($from, $to) {
|
||||
* Copies a directory from one location to another via the WordPress Filesystem Abstraction.
|
||||
* Assumes that WP_Filesystem() has already been called and setup.
|
||||
*
|
||||
* This is a temporary function for the 3.1 -> 3.2 upgrade only and will be removed in 3.3
|
||||
* This is a temporary function for the 3.1 -> 3.2 upgrade, as well as for those upgrading to
|
||||
* 3.7+
|
||||
*
|
||||
* @ignore
|
||||
* @since 3.2.0
|
||||
* @since 3.7.0 Updated not to use a regular expression for the skip list
|
||||
* @see copy_dir()
|
||||
*
|
||||
* @param string $from source directory
|
||||
@@ -827,17 +876,9 @@ function _copy_dir($from, $to, $skip_list = array() ) {
|
||||
$from = trailingslashit($from);
|
||||
$to = trailingslashit($to);
|
||||
|
||||
$skip_regex = '';
|
||||
foreach ( (array)$skip_list as $key => $skip_file )
|
||||
$skip_regex .= preg_quote($skip_file, '!') . '|';
|
||||
|
||||
if ( !empty($skip_regex) )
|
||||
$skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
|
||||
|
||||
foreach ( (array) $dirlist as $filename => $fileinfo ) {
|
||||
if ( !empty($skip_regex) )
|
||||
if ( preg_match($skip_regex, $from . $filename) )
|
||||
continue;
|
||||
if ( in_array( $filename, $skip_list ) )
|
||||
continue;
|
||||
|
||||
if ( 'f' == $fileinfo['type'] ) {
|
||||
if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
|
||||
@@ -851,7 +892,15 @@ function _copy_dir($from, $to, $skip_list = array() ) {
|
||||
if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
|
||||
return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
|
||||
}
|
||||
$result = _copy_dir($from . $filename, $to . $filename, $skip_list);
|
||||
|
||||
// generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list
|
||||
$sub_skip_list = array();
|
||||
foreach ( $skip_list as $skip_item ) {
|
||||
if ( 0 === strpos( $skip_item, $filename . '/' ) )
|
||||
$sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
|
||||
}
|
||||
|
||||
$result = _copy_dir($from . $filename, $to . $filename, $sub_skip_list);
|
||||
if ( is_wp_error($result) )
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user