Make WordPress Core

Changeset 55220


Ignore:
Timestamp:
02/04/2023 03:29:43 AM (16 months ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r55055 r55220  
    430430     *
    431431     * @since 2.8.0
     432     * @since 6.2.0 Use move_dir() instead of copy_dir() when possible.
    432433     *
    433434     * @global WP_Filesystem_Base $wp_filesystem        WordPress filesystem subclass.
     
    587588        }
    588589
    589         // Create destination if needed.
    590         if ( ! $wp_filesystem->exists( $remote_destination ) ) {
    591             if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
    592                 return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
    593             }
    594         }
    595 
    596         // Copy new version of item into place.
    597         $result = copy_dir( $source, $remote_destination );
     590        /*
     591         * Partial updates may want to retain the destination.
     592         * move_dir() returns a WP_Error when the destination exists,
     593         * so copy_dir() should be used.
     594         *
     595         * If 'clear_working' is false, the source shouldn't be removed.
     596         * After move_dir() runs, the source will no longer exist.
     597         * Therefore, copy_dir() should be used.
     598         */
     599        if ( $clear_destination && $args['clear_working'] ) {
     600            $result = move_dir( $source, $remote_destination, true );
     601        } else {
     602            // Create destination if needed.
     603            if ( ! $wp_filesystem->exists( $remote_destination ) ) {
     604                if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
     605                    return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
     606                }
     607            }
     608            $result = copy_dir( $source, $remote_destination );
     609        }
    598610
    599611        // Clear the working folder?
Note: See TracChangeset for help on using the changeset viewer.