Make WordPress Core

Ticket #36710: 36710.5.diff

File 36710.5.diff, 2.5 KB (added by bookdude13, 5 years ago)

Fix strtoupper typo

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

    diff --git src/wp-admin/includes/class-wp-filesystem-direct.php src/wp-admin/includes/class-wp-filesystem-direct.php
    index 1676a55658..f359e7207e 100644
    class WP_Filesystem_Direct extends WP_Filesystem_Base { 
    333333                }
    334334                $file = str_replace( '\\', '/', $file ); // For Win32, occasional problems deleting files otherwise.
    335335
    336                 if ( 'f' == $type || $this->is_file( $file ) ) {
    337                         return @unlink( $file );
     336                if ( 'f' == $type || $this->is_file( $file ) || $this->is_link( $file ) ) {
     337                        if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) &&
     338                                        $this->is_link( $file ) && $this->is_dir( $file ) ) {
     339                                // on windows unlink()'ing a symlink that points to a directory fails.
     340                                // @link https://bugs.php.net/bug.php?id=52176
     341                                return @rmdir( $file );
     342                        }
     343                        else {
     344                                // untrailingslashit() needed to remove symlinks successfully.
     345                                return @unlink( untrailingslashit( $file ) );
     346                        }
    338347                }
    339348                if ( ! $recursive && $this->is_dir( $file ) ) {
    340349                        return @rmdir( $file );
    class WP_Filesystem_Direct extends WP_Filesystem_Base { 
    372381                return @file_exists( $file );
    373382        }
    374383
     384        /**
     385         * Checks if resource is a symbolic link.
     386         *
     387         * @since 5.5.0
     388         *
     389         * @param string $file File path.
     390         * @return bool Whther `$file` is a symbolic link.
     391         */
     392        public function is_link( $file ) {
     393                // Strip trailing slashes, to avoid directory symlinks resolving.
     394                return @is_link( untrailingslashit( $file ) );
     395        }
     396
    375397        /**
    376398         * Checks if resource is a file.
    377399         *
    class WP_Filesystem_Direct extends WP_Filesystem_Base { 
    558580         * }
    559581         */
    560582        public function dirlist( $path, $include_hidden = true, $recursive = false ) {
    561                 if ( $this->is_file( $path ) ) {
     583                if ( $this->is_dir( $path ) && $this->is_link( $path ) ) {
     584                        // Directory is a symlink, therefore return no listing.
     585                        return array();
     586                }
     587                elseif ( $this->is_file( $path ) || $this->is_link( $path ) ) {
    562588                        $limit_file = basename( $path );
    563589                        $path       = dirname( $path );
    564590                } else {
    class WP_Filesystem_Direct extends WP_Filesystem_Base { 
    603629                        $struc['time']        = gmdate( 'h:i:s', $struc['lastmodunix'] );
    604630                        $struc['type']        = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
    605631
    606                         if ( 'd' == $struc['type'] ) {
     632                        if ( 'd' == $struc['type'] && ! $this->is_link( $path . '/' . $struc['name'] ) ) {
    607633                                if ( $recursive ) {
    608634                                        $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
    609635                                } else {