mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Filesystem API: Simplify two conditionals in move_dir()
.
This updates the check whether the destination directory already exists to only call `$wp_filesystem->exists()` once. Follow-up to [55204], [55219], [55220]. Props azaozz, afragen, SergeyBiryukov. Fixes #57375. Built from https://develop.svn.wordpress.org/trunk@55223 git-svn-id: http://core.svn.wordpress.org/trunk@54756 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cb4b7b6a8b
commit
4b790e3483
@ -1971,19 +1971,16 @@ function move_dir( $from, $to, $overwrite = false ) {
|
||||
global $wp_filesystem;
|
||||
|
||||
if ( trailingslashit( strtolower( $from ) ) === trailingslashit( strtolower( $to ) ) ) {
|
||||
return new WP_Error(
|
||||
'source_destination_same_move_dir',
|
||||
__( 'The source and destination are the same.' )
|
||||
);
|
||||
return new WP_Error( 'source_destination_same_move_dir', __( 'The source and destination are the same.' ) );
|
||||
}
|
||||
|
||||
if ( ! $overwrite && $wp_filesystem->exists( $to ) ) {
|
||||
return new WP_Error( 'destination_already_exists_move_dir', __( 'The destination folder already exists.' ), $to );
|
||||
}
|
||||
|
||||
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->exists( $to ) ) {
|
||||
if ( ! $overwrite ) {
|
||||
return new WP_Error( 'destination_already_exists_move_dir', __( 'The destination folder already exists.' ), $to );
|
||||
} elseif ( ! $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 ) ) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.2-alpha-55222';
|
||||
$wp_version = '6.2-alpha-55223';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user