Make WordPress Core

Ticket #51170: 51170.diff

File 51170.diff, 1.6 KB (added by mkox, 4 years ago)

exists improved, will fallback to ftp_size and Fixes #28013

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

    diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpext.php b/src/wp-admin/includes/class-wp-filesystem-ftpext.php
    index 627128fcac..f2e9532f08 100644
    a b class WP_Filesystem_FTPext extends WP_Filesystem_Base { 
    409409        }
    410410
    411411        /**
    412          * Checks if a file or directory exists.
     412         * Checks if a path exists.
    413413         *
    414414         * @since 2.5.0
    415415         *
    416          * @param string $file Path to file or directory.
    417          * @return bool Whether $file exists or not.
     416         * @param string $path Path to file or directory.
     417         * @return bool Whether $path exists or not.
    418418         */
    419         public function exists( $file ) {
    420                 $list = ftp_nlist( $this->link, $file );
     419        public function exists( $path ) {
    421420
    422                 if ( empty( $list ) && $this->is_dir( $file ) ) {
    423                         return true; // File is an empty directory.
     421                /**
     422                 * As is_dir tries to change in the dir it implicitly
     423                 * ensures existance of dir.
     424                 */
     425                if ( $this->is_dir( $path ) ) {
     426                        return true;
    424427                }
     428                else {
     429
     430                        try {
     431                                /**
     432                                 * Check for hidden file
     433                                 *
     434                                 * @ticket 28013
     435                                 */
     436                                $basename = basename( $path );
     437                                if ( substr( $basename, 0, 1 ) === "." ) {
     438                                        $path = '-a ' . $path; 
     439                                }
    425440
    426                 return ! empty( $list ); // Empty list = no file, so invert.
     441                                $list = ftp_nlist( $this->link, $path );
     442
     443                                return ! empty( $list ); // Empty list = no file, so invert.
     444                        }
     445
     446                        /**
     447                         * If ftp_nlist is not working, try ftp_size
     448                         *
     449                         * @ticket 51170
     450                         */
     451                        catch ( Exception $ex ) {
     452                                $size = ftp_size( $this->link, $path );
     453
     454                                return $size > -1;
     455                        }
     456                }
    427457        }
    428458
    429459        /**