Make WordPress Core

Changeset 55219


Ignore:
Timestamp:
02/04/2023 01:06:57 AM (2 years ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

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

    r55210 r55219  
    19561956 * Assumes that WP_Filesystem() has already been called and setup.
    19571957 *
     1958 * This function is not designed to merge directories, copy_dir() should be used instead.
     1959 *
    19581960 * @since 6.2.0
    19591961 *
     
    19801982    }
    19811983
    1982     if ( $wp_filesystem->move( $from, $to, $overwrite ) ) {
     1984    if ( $overwrite && $wp_filesystem->exists( $to ) && ! $wp_filesystem->delete( $to, true ) ) {
     1985        // Can't overwrite if the destination couldn't be deleted.
     1986        return WP_Error( 'destination_not_deleted_move_dir', __( 'The destination directory already exists and could not be removed.' ) );
     1987    }
     1988
     1989    if ( $wp_filesystem->move( $from, $to ) ) {
    19831990        /*
    19841991         * When using an environment with shared folders,
Note: See TracChangeset for help on using the changeset viewer.