Make WordPress Core

Changeset 55223


Ignore:
Timestamp:
02/04/2023 03:35:29 PM (16 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r55219 r55223  
    19721972
    19731973    if ( trailingslashit( strtolower( $from ) ) === trailingslashit( strtolower( $to ) ) ) {
    1974         return new WP_Error(
    1975             'source_destination_same_move_dir',
    1976             __( 'The source and destination are the same.' )
    1977         );
    1978     }
    1979 
    1980     if ( ! $overwrite && $wp_filesystem->exists( $to ) ) {
    1981         return new WP_Error( 'destination_already_exists_move_dir', __( 'The destination folder already exists.' ), $to );
    1982     }
    1983 
    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.' ) );
     1974        return new WP_Error( 'source_destination_same_move_dir', __( 'The source and destination are the same.' ) );
     1975    }
     1976
     1977    if ( $wp_filesystem->exists( $to ) ) {
     1978        if ( ! $overwrite ) {
     1979            return new WP_Error( 'destination_already_exists_move_dir', __( 'The destination folder already exists.' ), $to );
     1980        } elseif ( ! $wp_filesystem->delete( $to, true ) ) {
     1981            // Can't overwrite if the destination couldn't be deleted.
     1982            return WP_Error( 'destination_not_deleted_move_dir', __( 'The destination directory already exists and could not be removed.' ) );
     1983        }
    19871984    }
    19881985
Note: See TracChangeset for help on using the changeset viewer.