From 8cf4b7557f71996a90eb4fe4593a0941bd3f2df8 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 4 Feb 2023 01:08:17 +0000 Subject: [PATCH] Filesystem API: Update `move_dir()` to better handle the differences in the `WP_Filesystem::move()` methods. Changes `move_dir()` to attempt to delete the destination when overwriting, before calling `WP_Filesystem::move()`. Props: afragen, costdev, azaozz. Fixes: #57375. Built from https://develop.svn.wordpress.org/trunk@55219 git-svn-id: http://core.svn.wordpress.org/trunk@54752 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 9 ++++++++- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 6d22898b9c..13f04f05d4 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -1955,6 +1955,8 @@ function copy_dir( $from, $to, $skip_list = array() ) { * * Assumes that WP_Filesystem() has already been called and setup. * + * This function is not designed to merge directories, copy_dir() should be used instead. + * * @since 6.2.0 * * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. @@ -1979,7 +1981,12 @@ function move_dir( $from, $to, $overwrite = false ) { return new WP_Error( 'destination_already_exists_move_dir', __( 'The destination folder already exists.' ), $to ); } - if ( $wp_filesystem->move( $from, $to, $overwrite ) ) { + if ( $overwrite && $wp_filesystem->exists( $to ) && ! $wp_filesystem->delete( $to, true ) ) { + // Can't overwrite if the destination couldn't be deleted. + return WP_Error( 'destination_not_deleted_move_dir', __( 'The destination directory already exists and could not be removed.' ) ); + } + + if ( $wp_filesystem->move( $from, $to ) ) { /* * When using an environment with shared folders, * there is a delay in updating the filesystem's cache. diff --git a/wp-includes/version.php b/wp-includes/version.php index 97e0394543..443b142a2b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55218'; +$wp_version = '6.2-alpha-55219'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.