From 552a0c71a8e69dffa530f3f0d8ddc094ddecaebe Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 4 Feb 2023 03:31:16 +0000 Subject: [PATCH] Upgrade/Install: Use `move_dir()` instead of `copy_dir()` in `WP_Upgrader::install_package()` when possible. This would make the filesystem operations a lot faster in most cases, and potentially reduce failures. Props: afragen, costdev, peterwilsoncc, pbiron, mukesh27, SergeyBiryukov, azaozz. Fixes: #57557. Built from https://develop.svn.wordpress.org/trunk@55220 git-svn-id: http://core.svn.wordpress.org/trunk@54753 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader.php | 26 ++++++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index c1d65972c8..2437ac9625 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -429,6 +429,7 @@ class WP_Upgrader { * clear out the destination folder if it already exists. * * @since 2.8.0 + * @since 6.2.0 Use move_dir() instead of copy_dir() when possible. * * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. * @global array $wp_theme_directories @@ -586,16 +587,27 @@ class WP_Upgrader { } } - // Create destination if needed. - if ( ! $wp_filesystem->exists( $remote_destination ) ) { - if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) { - return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination ); + /* + * Partial updates may want to retain the destination. + * move_dir() returns a WP_Error when the destination exists, + * so copy_dir() should be used. + * + * If 'clear_working' is false, the source shouldn't be removed. + * After move_dir() runs, the source will no longer exist. + * Therefore, copy_dir() should be used. + */ + if ( $clear_destination && $args['clear_working'] ) { + $result = move_dir( $source, $remote_destination, true ); + } else { + // Create destination if needed. + if ( ! $wp_filesystem->exists( $remote_destination ) ) { + if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) { + return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination ); + } } + $result = copy_dir( $source, $remote_destination ); } - // Copy new version of item into place. - $result = copy_dir( $source, $remote_destination ); - // Clear the working folder? if ( $args['clear_working'] ) { $wp_filesystem->delete( $remote_source, true ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 443b142a2b..6019736e92 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55219'; +$wp_version = '6.2-alpha-55220'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.