Make WordPress Core


Ignore:
Timestamp:
10/09/2021 03:37:41 AM (3 years ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Introduce a move_dir() function.

This replaces the copy_dir() usage in WP_Upgrader::install_package() and aims to avoid PHP timeout issues when installing or updating large plugins on slower systems like Vagrant or the WP Docker test environment.

The new function attempts a native PHP rename() function first and falls back to the previous copy_dir().

Follow-up to [51815], [51898].

Props afragen, aristath, peterwilsoncc, galbaras, noisysocks, pbiron.
Fixes #54166. See #51857.

File:
1 edited

Legend:

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

    r51626 r51899  
    19191919
    19201920/**
     1921 * Moves a directory from one location to another via the rename() PHP function.
     1922 * If the renaming failed, falls back to copy_dir().
     1923 *
     1924 * Assumes that WP_Filesystem() has already been called and setup.
     1925 *
     1926 * @since 5.9.0
     1927 *
     1928 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
     1929 *
     1930 * @param string $from Source directory.
     1931 * @param string $to   Destination directory.
     1932 * @return true|WP_Error True on success, WP_Error on failure.
     1933 */
     1934function move_dir( $from, $to ) {
     1935    global $wp_filesystem;
     1936
     1937    $wp_filesystem->rmdir( $to );
     1938    if ( @rename( $from, $to ) ) {
     1939        return true;
     1940    }
     1941
     1942    $wp_filesystem->mkdir( $to );
     1943    $result = copy_dir( $from, $to );
     1944
     1945    return $result;
     1946}
     1947
     1948/**
    19211949 * Initializes and connects the WordPress Filesystem Abstraction classes.
    19221950 *
Note: See TracChangeset for help on using the changeset viewer.