From 14b4579d98ed37ab1200f00fd40e3cf09f3c443d Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 1 Mar 2014 06:00:47 +0000 Subject: [PATCH] Upgrader: Copy wp-includes/version.php over last, to avoid an installation failing with the new version.php in place. Fixes #25860 git-svn-id: https://develop.svn.wordpress.org/trunk@27336 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/update-core.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php index bcc83034be..b4ea9a13e4 100644 --- a/src/wp-admin/includes/update-core.php +++ b/src/wp-admin/includes/update-core.php @@ -748,7 +748,8 @@ function update_core($from, $to) { 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' ); + // We also copy version.php last so failed updates report their old version + $skip = array( 'wp-content', 'wp-includes/version.php' ); $check_is_writable = array(); // Check to see which files don't really need updating - only available for 3.7 and higher @@ -810,6 +811,15 @@ function update_core($from, $to) { if ( is_wp_error( $result ) ) $result = new WP_Error( $result->get_error_code(), $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) ); + // Since we know the core files have copied over, we can now copy the version file + if ( ! is_wp_error( $result ) ) { + if ( ! $r = $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $to . 'wp-includes/version.php', true /* overwrite */ ) ) { + $wp_filesystem->delete( $from, true ); + $result = new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'WTFwp-includes/version.php' ); + } + $wp_filesystem->chmod( $to . 'wp-includes/version.php', FS_CHMOD_FILE ); + } + // Check to make sure everything copied correctly, ignoring the contents of wp-content $skip = array( 'wp-content' ); $failed = array();