Make WordPress Core

Changeset 45177


Ignore:
Timestamp:
04/12/2019 08:00:42 PM (6 years ago)
Author:
joemcgill
Message:

Media: Fix deletion of files when using stream wrappers.

This fixes a bug introduced in [43392] which breaks file deletion on systems using stream wrappers, due to limitations of realpath().

Props antonypuckey, pfiled.
Fixes #44563.

File:
1 edited

Legend:

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

    r45137 r45177  
    18311831 */
    18321832function path_is_absolute( $path ) {
     1833    /*
     1834     * Check to see if the path is a stream and check to see if its an actual
     1835     * path or file as realpath() does not support stream wrappers.
     1836     */
     1837    if ( wp_is_stream( $path ) && ( is_dir( $path ) || is_file( $path ) ) ) {
     1838        return true;
     1839    }
     1840
    18331841    /*
    18341842     * This is definitive if true but fails if $path does not exist or contains
     
    62706278 */
    62716279function wp_delete_file_from_directory( $file, $directory ) {
    6272     $real_file      = realpath( wp_normalize_path( $file ) );
    6273     $real_directory = realpath( wp_normalize_path( $directory ) );
    6274 
    6275     if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) {
     6280    if ( wp_is_stream( $file ) ) {
     6281        $real_file      = wp_normalize_path( $file );
     6282        $real_directory = wp_normalize_path( $directory );
     6283    } else {
     6284        $real_file      = realpath( wp_normalize_path( $file ) );
     6285        $real_directory = realpath( wp_normalize_path( $directory ) );
     6286    }
     6287
     6288    if ( false === $real_file || false === $real_directory || strpos( $real_file, trailingslashit( $real_directory ) ) !== 0 ) {
    62766289        return false;
    62776290    }
Note: See TracChangeset for help on using the changeset viewer.