Make WordPress Core

Changeset 54143


Ignore:
Timestamp:
09/13/2022 04:56:00 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Remove _copy_dir() function as originally intended.

WordPress 3.2 introduced several enhancements to the copy_dir() function:

  • No more re-installing Akismet upon upgrade.
  • Respect custom WP_CONTENT_DIR for bundled plugins/theme installation.
  • Respect custom WP_CONTENT_DIR/WP_LANG_DIR for language files when upgrading.
  • Add an exclusion list to copy_dir() as well as WP_Filesystem_Base::wp_lang_dir().
  • Standardize WP_Filesystem path method returns.

However, the version of copy_dir() that runs during the upgrade process is the one from the older install, not the newer, which means that these enhancements would only be available after upgrading to WordPress 3.2 first, e.g. in a subsequent upgrade to WordPress 3.3.

In order to make these enhancements immediately available in WordPress 3.2, specifically to take advantage of skip lists and avoid re-installing Akismet if it was previously deleted, a temporary copy of the function was utilized, with the intention to remove it in WordPress 3.3 or a later release.

With further enhancements made to the Upgrade API to support partial and no-content builds, this temporary copy is no longer relevant and can be safely removed.

Follow-up to [17576], [17580], [17581], [18225].

Props afragen, costdev, dd32, peterwilsoncc, SergeyBiryukov.
Fixes #55712. See #17173.

File:
1 edited

Legend:

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

    r53439 r54143  
    11891189
    11901190    // Copy new versions of WP files into place.
    1191     $result = _copy_dir( $from . $distro, $to, $skip );
     1191    $result = copy_dir( $from . $distro, $to, $skip );
    11921192
    11931193    if ( is_wp_error( $result ) ) {
     
    12671267            $result = new WP_Error( 'disk_full', __( 'There is not enough free disk space to complete the update.' ) );
    12681268        } else {
    1269             $result = _copy_dir( $from . $distro, $to, $skip );
     1269            $result = copy_dir( $from . $distro, $to, $skip );
    12701270
    12711271            if ( is_wp_error( $result ) ) {
     
    14581458
    14591459    return $wp_version;
    1460 }
    1461 
    1462 /**
    1463  * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
    1464  *
    1465  * Assumes that WP_Filesystem() has already been called and setup.
    1466  *
    1467  * This is a standalone copy of the `copy_dir()` function that is used to
    1468  * upgrade the core files. It is placed here so that the version of this
    1469  * function from the *new* WordPress version will be called.
    1470  *
    1471  * It was initially added for the 3.1 -> 3.2 upgrade.
    1472  *
    1473  * @ignore
    1474  * @since 3.2.0
    1475  * @since 3.7.0 Updated not to use a regular expression for the skip list.
    1476  *
    1477  * @see copy_dir()
    1478  * @link https://core.trac.wordpress.org/ticket/17173
    1479  *
    1480  * @global WP_Filesystem_Base $wp_filesystem
    1481  *
    1482  * @param string   $from      Source directory.
    1483  * @param string   $to        Destination directory.
    1484  * @param string[] $skip_list Array of files/folders to skip copying.
    1485  * @return true|WP_Error True on success, WP_Error on failure.
    1486  */
    1487 function _copy_dir( $from, $to, $skip_list = array() ) {
    1488     global $wp_filesystem;
    1489 
    1490     $dirlist = $wp_filesystem->dirlist( $from );
    1491 
    1492     if ( false === $dirlist ) {
    1493         return new WP_Error( 'dirlist_failed__copy_dir', __( 'Directory listing failed.' ), basename( $to ) );
    1494     }
    1495 
    1496     $from = trailingslashit( $from );
    1497     $to   = trailingslashit( $to );
    1498 
    1499     foreach ( (array) $dirlist as $filename => $fileinfo ) {
    1500         if ( in_array( $filename, $skip_list, true ) ) {
    1501             continue;
    1502         }
    1503 
    1504         if ( 'f' === $fileinfo['type'] ) {
    1505             if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) {
    1506                 // If copy failed, chmod file to 0644 and try again.
    1507                 $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
    1508 
    1509                 if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) {
    1510                     return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
    1511                 }
    1512             }
    1513 
    1514             /*
    1515              * `wp_opcache_invalidate()` only exists in WordPress 5.5 or later,
    1516              * so don't run it when upgrading from older versions.
    1517              */
    1518             if ( function_exists( 'wp_opcache_invalidate' ) ) {
    1519                 wp_opcache_invalidate( $to . $filename );
    1520             }
    1521         } elseif ( 'd' === $fileinfo['type'] ) {
    1522             if ( ! $wp_filesystem->is_dir( $to . $filename ) ) {
    1523                 if ( ! $wp_filesystem->mkdir( $to . $filename, FS_CHMOD_DIR ) ) {
    1524                     return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );
    1525                 }
    1526             }
    1527 
    1528             /*
    1529              * Generate the $sub_skip_list for the subdirectory as a sub-set
    1530              * of the existing $skip_list.
    1531              */
    1532             $sub_skip_list = array();
    1533 
    1534             foreach ( $skip_list as $skip_item ) {
    1535                 if ( 0 === strpos( $skip_item, $filename . '/' ) ) {
    1536                     $sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
    1537                 }
    1538             }
    1539 
    1540             $result = _copy_dir( $from . $filename, $to . $filename, $sub_skip_list );
    1541 
    1542             if ( is_wp_error( $result ) ) {
    1543                 return $result;
    1544             }
    1545         }
    1546     }
    1547 
    1548     return true;
    15491460}
    15501461
Note: See TracChangeset for help on using the changeset viewer.