Make WordPress Core

Ticket #36710: 36710.2.diff

File 36710.2.diff, 2.2 KB (added by pbiron, 6 years ago)

refreshes fix-symlinks.diff

  • src/wp-admin/includes/class-wp-filesystem-direct.php

    diff --git a/src/wp-admin/includes/class-wp-filesystem-direct.php b/src/wp-admin/includes/class-wp-filesystem-direct.php
    index 9b1757cc65..ec646a8bb6 100644
    a b class WP_Filesystem_Direct extends WP_Filesystem_Base { 
    332332                }
    333333                $file = str_replace( '\\', '/', $file ); // for win32, occasional problems deleting files otherwise
    334334
    335                 if ( 'f' == $type || $this->is_file( $file ) ) {
    336                         return @unlink( $file );
     335                if ( 'f' == $type || $this->is_file( $file ) || $this->is_link( $file ) ) {
     336                        // rtrim() needed to remove symlinks successfully.
     337                        return @unlink( rtrim( $file, '/' ) );
    337338                }
    338339                if ( ! $recursive && $this->is_dir( $file ) ) {
    339340                        return @rmdir( $file );
    class WP_Filesystem_Direct extends WP_Filesystem_Base { 
    383384                return @is_file( $file );
    384385        }
    385386
     387        /**
     388         * Checks if resource is a symbolic link.
     389         *
     390         * @since 5.3.0
     391         *
     392         * @param string $file File path.
     393         * @return bool Whether $file is a symbolic link.
     394         */
     395        public function is_link( $file ) {
     396                // Strip trailing slashes, to avoid directory symlinks resolving.
     397                return @is_link( rtrim( $file, '/' ) );
     398        }
     399
    386400        /**
    387401         * Checks if resource is a directory.
    388402         *
    class WP_Filesystem_Direct extends WP_Filesystem_Base { 
    557571         * }
    558572         */
    559573        public function dirlist( $path, $include_hidden = true, $recursive = false ) {
    560                 if ( $this->is_file( $path ) ) {
     574                if ( $this->is_dir( $path ) && $this->is_link( $path ) ) {
     575                        // Directory is symlink, therefore return no listing.
     576                        return array();
     577                }
     578                elseif ( $this->is_file( $path ) || $this->is_link( $path ) ) {
    561579                        $limit_file = basename( $path );
    562580                        $path       = dirname( $path );
    563581                } else {
    class WP_Filesystem_Direct extends WP_Filesystem_Base { 
    602620                        $struc['time']        = gmdate( 'h:i:s', $struc['lastmodunix'] );
    603621                        $struc['type']        = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
    604622
    605                         if ( 'd' == $struc['type'] ) {
     623                        if ( 'd' == $struc['type'] && ! $this->is_link( $path . '/' . $struc['name'] ) ) {
    606624                                if ( $recursive ) {
    607625                                        $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
    608626                                } else {