From ba4ed5f86c304a76a5a551bcf3e12fd0e1daf7c0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 6 Feb 2023 14:48:16 +0000 Subject: [PATCH] Upgrade/Install: Send language pack updates to `copy_dir()`. If the `clear_working` flag in `WP_Upgrader::install_package()` is false, the source should not be removed, so `copy_dir()` should be used instead. Partial updates, like language packs, may want to retain the destination. If the destination exists or has contents, this may be a partial update, and the destination should not be removed, so `copy_dir()` should be used instead. Follow-up to [55204], [55219], [55220], [55223], [55226]. Props afragen, costdev, swissspidy. See #57557. Built from https://develop.svn.wordpress.org/trunk@55229 git-svn-id: http://core.svn.wordpress.org/trunk@54762 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader.php | 18 +++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 2437ac9625..1b2df949cf 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -588,15 +588,19 @@ class WP_Upgrader { } /* - * 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 should not be removed, so use copy_dir() instead. * - * 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. + * Partial updates, like language packs, may want to retain the destination. + * If the destination exists or has contents, this may be a partial update, + * and the destination should not be removed, so use copy_dir() instead. */ - if ( $clear_destination && $args['clear_working'] ) { + if ( $args['clear_working'] + && ( + // Destination does not exist or has no contents. + ! $wp_filesystem->exists( $remote_destination ) + || empty( $wp_filesystem->dirlist( $remote_destination ) ) + ) + ) { $result = move_dir( $source, $remote_destination, true ); } else { // Create destination if needed. diff --git a/wp-includes/version.php b/wp-includes/version.php index 6b7b26f060..f1bfca4c0e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55228'; +$wp_version = '6.2-alpha-55229'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.