Changeset 54143
- Timestamp:
- 09/13/2022 04:56:00 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/update-core.php
r53439 r54143 1189 1189 1190 1190 // Copy new versions of WP files into place. 1191 $result = _copy_dir( $from . $distro, $to, $skip );1191 $result = copy_dir( $from . $distro, $to, $skip ); 1192 1192 1193 1193 if ( is_wp_error( $result ) ) { … … 1267 1267 $result = new WP_Error( 'disk_full', __( 'There is not enough free disk space to complete the update.' ) ); 1268 1268 } else { 1269 $result = _copy_dir( $from . $distro, $to, $skip );1269 $result = copy_dir( $from . $distro, $to, $skip ); 1270 1270 1271 1271 if ( is_wp_error( $result ) ) { … … 1458 1458 1459 1459 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 to1468 * upgrade the core files. It is placed here so that the version of this1469 * function from the *new* WordPress version will be called.1470 *1471 * It was initially added for the 3.1 -> 3.2 upgrade.1472 *1473 * @ignore1474 * @since 3.2.01475 * @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/171731479 *1480 * @global WP_Filesystem_Base $wp_filesystem1481 *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-set1530 * 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;1549 1460 } 1550 1461
Note: See TracChangeset
for help on using the changeset viewer.