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
This commit is contained in:
Andrew Ozz 2023-02-04 03:31:16 +00:00
parent 8cf4b7557f
commit 552a0c71a8
2 changed files with 20 additions and 8 deletions

View File

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

View File

@ -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.