Make WordPress Core

Changeset 48089


Ignore:
Timestamp:
06/19/2020 10:34:26 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Add some space around control structures in WP_Filesystem_* classes for consistency and better readability.

Additionally, synchronize $tempfile and $temphandle variable names in WP_Filesystem_FTPext and WP_Filesystem_ftpsockets.

See #49542.

Location:
trunk/src/wp-admin/includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-filesystem-base.php

    r47808 r48089  
    5656        public function abspath() {
    5757                $folder = $this->find_folder( ABSPATH );
     58
    5859                // Perhaps the FTP folder is rooted at the WordPress install.
    5960                // Check for wp-includes folder in root. Could have some false positives, but rare.
    … …  
    6162                        $folder = '/';
    6263                }
     64
    6365                return $folder;
    6466        }
    … …  
    189191                                        continue;
    190192                                }
     193
    191194                                if ( $folder === $dir ) {
    192195                                        return trailingslashit( constant( $constant ) );
    … …  
    199202                                        continue;
    200203                                }
     204
    201205                                if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir.
    202206                                        $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );
    … …  
    205209                                        if ( $this->is_dir( $potential_folder ) ) {
    206210                                                $this->cache[ $folder ] = $potential_folder;
     211
    207212                                                return $potential_folder;
    208213                                        }
    … …  
    211216                } elseif ( 'direct' === $this->method ) {
    212217                        $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation.
     218
    213219                        return trailingslashit( $folder );
    214220                }
    … …  
    224230                        $folder                 = trailingslashit( $folder );
    225231                        $this->cache[ $folder ] = $folder;
     232
    226233                        return $folder;
    227234                }
     235
    228236                $return = $this->search_for_folder( $folder );
     237
    229238                if ( $return ) {
    230239                        $this->cache[ $folder ] = $return;
    231240                }
     241
    232242                return $return;
    233243        }
    … …  
    280290                                // Let's try that folder:
    281291                                $newdir = trailingslashit( path_join( $base, $key ) );
     292
    282293                                if ( $this->verbose ) {
    283294                                        /* translators: %s: Directory name. */
    … …  
    288299                                $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
    289300                                $ret       = $this->search_for_folder( $newfolder, $newdir, $loop );
     301
    290302                                if ( $ret ) {
    291303                                        return $ret;
    … …  
    301313                                printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path );
    302314                        }
     315
    303316                        return trailingslashit( $base . $last_path );
    304317                }
    … …  
    330343        public function gethchmod( $file ) {
    331344                $perms = intval( $this->getchmod( $file ), 8 );
     345
    332346                if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket.
    333347                        $info = 's';
    … …  
    368382                                        ( ( $perms & 0x0200 ) ? 't' : 'x' ) :
    369383                                        ( ( $perms & 0x0200 ) ? 'T' : '-' ) );
     384
    370385                return $info;
    371386        }
    … …  
    403418                for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
    404419                        $key = array_search( $attarray[ $i ], $legal, true );
     420
    405421                        if ( $key ) {
    406422                                $realmode .= $legal[ $key ];
    … …  
    421437                $newmode .= $mode[4] + $mode[5] + $mode[6];
    422438                $newmode .= $mode[7] + $mode[8] + $mode[9];
     439
    423440                return $newmode;
    424441        }
  • trunk/src/wp-admin/includes/class-wp-filesystem-direct.php

    r48031 r48089  
    6565        public function put_contents( $file, $contents, $mode = false ) {
    6666                $fp = @fopen( $file, 'wb' );
     67
    6768                if ( ! $fp ) {
    6869                        return false;
    … …  
    126127                        return false;
    127128                }
     129
    128130                if ( ! $recursive ) {
    129131                        return chgrp( $file, $group );
    130132                }
     133
    131134                if ( ! $this->is_dir( $file ) ) {
    132135                        return chgrp( $file, $group );
    133136                }
     137
    134138                // Is a directory, and we want recursive.
    135139                $file     = trailingslashit( $file );
    136140                $filelist = $this->dirlist( $file );
     141
    137142                foreach ( $filelist as $filename ) {
    138143                        $this->chgrp( $file . $filename, $group, $recursive );
    … …  
    168173                        return chmod( $file, $mode );
    169174                }
     175
    170176                // Is a directory, and we want recursive.
    171177                $file     = trailingslashit( $file );
    172178                $filelist = $this->dirlist( $file );
     179
    173180                foreach ( (array) $filelist as $filename => $filemeta ) {
    174181                        $this->chmod( $file . $filename, $mode, $recursive );
    … …  
    193200                        return false;
    194201                }
     202
    195203                if ( ! $recursive ) {
    196204                        return chown( $file, $owner );
    197205                }
     206
    198207                if ( ! $this->is_dir( $file ) ) {
    199208                        return chown( $file, $owner );
    200209                }
     210
    201211                // Is a directory, and we want recursive.
    202212                $filelist = $this->dirlist( $file );
     213
    203214                foreach ( $filelist as $filename ) {
    204215                        $this->chown( $file . '/' . $filename, $owner, $recursive );
    205216                }
     217
    206218                return true;
    207219        }
    … …  
    217229        public function owner( $file ) {
    218230                $owneruid = @fileowner( $file );
     231
    219232                if ( ! $owneruid ) {
    220233                        return false;
    221234                }
     235
    222236                if ( ! function_exists( 'posix_getpwuid' ) ) {
    223237                        return $owneruid;
    224238                }
     239
    225240                $ownerarray = posix_getpwuid( $owneruid );
     241
    226242                if ( ! $ownerarray ) {
    227243                        return false;
    228244                }
     245
    229246                return $ownerarray['name'];
    230247        }
    … …  
    254271        public function group( $file ) {
    255272                $gid = @filegroup( $file );
     273
    256274                if ( ! $gid ) {
    257275                        return false;
    258276                }
     277
    259278                if ( ! function_exists( 'posix_getgrgid' ) ) {
    260279                        return $gid;
    261280                }
     281
    262282                $grouparray = posix_getgrgid( $gid );
     283
    263284                if ( ! $grouparray ) {
    264285                        return false;
    265286                }
     287
    266288                return $grouparray['name'];
    267289        }
    … …  
    286308
    287309                $rtval = copy( $source, $destination );
     310
    288311                if ( $mode ) {
    289312                        $this->chmod( $destination, $mode );
    290313                }
     314
    291315                return $rtval;
    292316        }
    … …  
    315339                if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) {
    316340                        $this->delete( $source );
     341
    317342                        return true;
    318343                } else {
    … …  
    338363                        return false;
    339364                }
     365
    340366                $file = str_replace( '\\', '/', $file ); // For Win32, occasional problems deleting files otherwise.
    341367
    … …  
    343369                        return @unlink( $file );
    344370                }
     371
    345372                if ( ! $recursive && $this->is_dir( $file ) ) {
    346373                        return @rmdir( $file );
    … …  
    352379
    353380                $retval = true;
     381
    354382                if ( is_array( $filelist ) ) {
    355383                        foreach ( $filelist as $filename => $fileinfo ) {
    … …  
    481509                        $time = time();
    482510                }
     511
    483512                if ( 0 == $atime ) {
    484513                        $atime = time();
    485514                }
     515
    486516                return touch( $file, $time, $atime );
    487517        }
    … …  
    504534                // Safe mode fails with a trailing slash under certain PHP versions.
    505535                $path = untrailingslashit( $path );
     536
    506537                if ( empty( $path ) ) {
    507538                        return false;
    … …  
    515546                        return false;
    516547                }
     548
    517549                $this->chmod( $path, $chmod );
     550
    518551                if ( $chown ) {
    519552                        $this->chown( $path, $chown );
    520553                }
     554
    521555                if ( $chgrp ) {
    522556                        $this->chgrp( $path, $chgrp );
    523557                }
     558
    524559                return true;
    525560        }
    … …  
    577612
    578613                $dir = dir( $path );
     614
    579615                if ( ! $dir ) {
    580616                        return false;
    … …  
    620656                        $ret[ $struc['name'] ] = $struc;
    621657                }
     658
    622659                $dir->close();
    623660                unset( $dir );
     661
    624662                return $ret;
    625663        }
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php

    r47808 r48089  
    7070
    7171                $this->options['ssl'] = false;
     72
    7273                if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) {
    7374                        $this->options['ssl'] = true;
    … …  
    9899                                )
    99100                        );
     101
    100102                        return false;
    101103                }
    … …  
    110112                                )
    111113                        );
     114
    112115                        return false;
    113116                }
    … …  
    115118                // Set the connection to use Passive FTP.
    116119                ftp_pasv( $this->link, true );
     120
    117121                if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) {
    118122                        @ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT );
    … …  
    132136         */
    133137        public function get_contents( $file ) {
    134                 $tempfile = wp_tempnam( $file );
    135                 $temp    = fopen( $tempfile, 'w+' );
    136 
    137                 if ( ! $temp ) {
     138                $tempfile   = wp_tempnam( $file );
     139                $temphandle = fopen( $tempfile, 'w+' );
     140
     141                if ( ! $temphandle ) {
    138142                        unlink( $tempfile );
    139143                        return false;
    140144                }
    141145
    142                 if ( ! ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) {
    143                         fclose( $temp );
     146                if ( ! ftp_fget( $this->link, $temphandle, $file, FTP_BINARY ) ) {
     147                        fclose( $temphandle );
    144148                        unlink( $tempfile );
    145149                        return false;
    146150                }
    147151
    148                 fseek( $temp, 0 ); // Skip back to the start of the file being written to.
     152                fseek( $temphandle, 0 ); // Skip back to the start of the file being written to.
    149153                $contents = '';
    150154
    151                 while ( ! feof( $temp ) ) {
    152                         $contents .= fread( $temp, 8 * KB_IN_BYTES );
    153                 }
    154 
    155                 fclose( $temp );
     155                while ( ! feof( $temphandle ) ) {
     156                        $contents .= fread( $temphandle, 8 * KB_IN_BYTES );
     157                }
     158
     159                fclose( $temphangle );
    156160                unlink( $tempfile );
     161
    157162                return $contents;
    158163        }
    … …  
    182187         */
    183188        public function put_contents( $file, $contents, $mode = false ) {
    184                 $tempfile = wp_tempnam( $file );
    185                 $temp    = fopen( $tempfile, 'wb+' );
    186 
    187                 if ( ! $temp ) {
     189                $tempfile   = wp_tempnam( $file );
     190                $temphandle = fopen( $tempfile, 'wb+' );
     191
     192                if ( ! $temphandle ) {
    188193                        unlink( $tempfile );
    189194                        return false;
    … …  
    193198
    194199                $data_length   = strlen( $contents );
    195                 $bytes_written = fwrite( $temp, $contents );
     200                $bytes_written = fwrite( $temphandle, $contents );
    196201
    197202                reset_mbstring_encoding();
    198203
    199204                if ( $data_length !== $bytes_written ) {
    200                         fclose( $temp );
     205                        fclose( $temphandle );
    201206                        unlink( $tempfile );
    202207                        return false;
    203208                }
    204209
    205                 fseek( $temp, 0 ); // Skip back to the start of the file being written to.
    206 
    207                 $ret = ftp_fput( $this->link, $file, $temp, FTP_BINARY );
    208 
    209                 fclose( $temp );
     210                fseek( $temphandle, 0 ); // Skip back to the start of the file being written to.
     211
     212                $ret = ftp_fput( $this->link, $file, $temphandle, FTP_BINARY );
     213
     214                fclose( $temphandle );
    210215                unlink( $tempfile );
    211216
    … …  
    224229        public function cwd() {
    225230                $cwd = ftp_pwd( $this->link );
     231
    226232                if ( $cwd ) {
    227233                        $cwd = trailingslashit( $cwd );
    228234                }
     235
    229236                return $cwd;
    230237        }
    … …  
    268275                if ( $recursive && $this->is_dir( $file ) ) {
    269276                        $filelist = $this->dirlist( $file );
     277
    270278                        foreach ( (array) $filelist as $filename => $filemeta ) {
    271279                                $this->chmod( $file . '/' . $filename, $mode, $recursive );
    … …  
    277285                        return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) );
    278286                }
     287
    279288                return (bool) ftp_chmod( $this->link, $mode, $file );
    280289        }
    … …  
    290299        public function owner( $file ) {
    291300                $dir = $this->dirlist( $file );
     301
    292302                return $dir[ $file ]['owner'];
    293303        }
    … …  
    303313        public function getchmod( $file ) {
    304314                $dir = $this->dirlist( $file );
     315
    305316                return $dir[ $file ]['permsn'];
    306317        }
    … …  
    316327        public function group( $file ) {
    317328                $dir = $this->dirlist( $file );
     329
    318330                return $dir[ $file ]['group'];
    319331        }
    … …  
    336348                        return false;
    337349                }
     350
    338351                $content = $this->get_contents( $source );
     352
    339353                if ( false === $content ) {
    340354                        return false;
    341355                }
     356
    342357                return $this->put_contents( $destination, $content, $mode );
    343358        }
    … …  
    374389                        return false;
    375390                }
     391
    376392                if ( 'f' === $type || $this->is_file( $file ) ) {
    377393                        return ftp_delete( $this->link, $file );
    378394                }
     395
    379396                if ( ! $recursive ) {
    380397                        return ftp_rmdir( $this->link, $file );
    … …  
    382399
    383400                $filelist = $this->dirlist( trailingslashit( $file ) );
     401
    384402                if ( ! empty( $filelist ) ) {
    385403                        foreach ( $filelist as $delete_file ) {
    … …  
    387405                        }
    388406                }
     407
    389408                return ftp_rmdir( $this->link, $file );
    390409        }
    … …  
    431450                $cwd    = $this->cwd();
    432451                $result = @ftp_chdir( $this->link, trailingslashit( $path ) );
     452
    433453                if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
    434454                        @ftp_chdir( $this->link, $cwd );
    435455                        return true;
    436456                }
     457
    437458                return false;
    438459        }
    … …  
    532553        public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
    533554                $path = untrailingslashit( $path );
     555
    534556                if ( empty( $path ) ) {
    535557                        return false;
    … …  
    539561                        return false;
    540562                }
     563
    541564                $this->chmod( $path, $chmod );
     565
    542566                return true;
    543567        }
    … …  
    564588        public function parselisting( $line ) {
    565589                static $is_windows = null;
     590
    566591                if ( is_null( $is_windows ) ) {
    567592                        $is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false;
    … …  
    570595                if ( $is_windows && preg_match( '/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer ) ) {
    571596                        $b = array();
     597
    572598                        if ( $lucifer[3] < 70 ) {
    573599                                $lucifer[3] += 2000;
    … …  
    575601                                $lucifer[3] += 1900; // 4-digit year fix.
    576602                        }
     603
    577604                        $b['isdir'] = ( '<DIR>' === $lucifer[7] );
     605
    578606                        if ( $b['isdir'] ) {
    579607                                $b['type'] = 'd';
    … …  
    581609                                $b['type'] = 'f';
    582610                        }
     611
    583612                        $b['size']   = $lucifer[7];
    584613                        $b['month']  = $lucifer[1];
    … …  
    592621                } elseif ( ! $is_windows ) {
    593622                        $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY );
     623
    594624                        if ( $lucifer ) {
    595625                                // echo $line."\n";
    596626                                $lcount = count( $lucifer );
     627
    597628                                if ( $lcount < 8 ) {
    598629                                        return '';
    599630                                }
     631
    600632                                $b           = array();
    601633                                $b['isdir']  = 'd' === $lucifer[0][0];
    602634                                $b['islink'] = 'l' === $lucifer[0][0];
     635
    603636                                if ( $b['isdir'] ) {
    604637                                        $b['type'] = 'd';
    … …  
    608641                                        $b['type'] = 'f';
    609642                                }
     643
    610644                                $b['perms']  = $lucifer[0];
    611645                                $b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
    … …  
    614648                                $b['group']  = $lucifer[3];
    615649                                $b['size']   = $lucifer[4];
     650
    616651                                if ( 8 == $lcount ) {
    617652                                        sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] );
    618653                                        sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] );
     654
    619655                                        $b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
    620656                                        $b['name'] = $lucifer[7];
    … …  
    622658                                        $b['month'] = $lucifer[5];
    623659                                        $b['day']   = $lucifer[6];
     660
    624661                                        if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) {
    625662                                                $b['year']   = gmdate( 'Y' );
    … …  
    631668                                                $b['minute'] = 0;
    632669                                        }
     670
    633671                                        $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) );
    634672                                        $b['name'] = $lucifer[8];
    … …  
    679717
    680718                $pwd = ftp_pwd( $this->link );
     719
    681720                if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist.
    682721                        return false;
    683722                }
     723
    684724                $list = ftp_rawlist( $this->link, '-a', false );
     725
    685726                @ftp_chdir( $this->link, $pwd );
    686727
    … …  
    690731
    691732                $dirlist = array();
     733
    692734                foreach ( $list as $k => $v ) {
    693735                        $entry = $this->parselisting( $v );
     736
    694737                        if ( empty( $entry ) ) {
    695738                                continue;
    … …  
    712755
    713756                $ret = array();
     757
    714758                foreach ( (array) $dirlist as $struc ) {
    715759                        if ( 'd' === $struc['type'] ) {
    … …  
    723767                        $ret[ $struc['name'] ] = $struc;
    724768                }
     769
    725770                return $ret;
    726771        }
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r47808 r48089  
    3737                        return;
    3838                }
     39
    3940                $this->ftp = new ftp();
    4041
    … …  
    8889                                )
    8990                        );
     91
    9092                        return false;
    9193                }
    … …  
    100102                                )
    101103                        );
     104
    102105                        return false;
    103106                }
    … …  
    112115                                )
    113116                        );
     117
    114118                        return false;
    115119                }
    … …  
    118122                $this->ftp->Passive( true );
    119123                $this->ftp->setTimeout( FS_TIMEOUT );
     124
    120125                return true;
    121126        }
    … …  
    135140                }
    136141
    137                 $temp = wp_tempnam( $file );
    138 
    139                 $temphandle = fopen( $temp, 'w+' );
     142                $tempfile  = wp_tempnam( $file );
     143                $temphandle = fopen( $tempfile, 'w+' );
     144
    140145                if ( ! $temphandle ) {
    141                         unlink( $temp );
     146                        unlink( $tempfile );
    142147                        return false;
    143148                }
    … …  
    147152                if ( ! $this->ftp->fget( $temphandle, $file ) ) {
    148153                        fclose( $temphandle );
    149                         unlink( $temp );
     154                        unlink( $tempfile );
    150155
    151156                        reset_mbstring_encoding();
    … …  
    164169
    165170                fclose( $temphandle );
    166                 unlink( $temp );
     171                unlink( $tempfile );
     172
    167173                return $contents;
    168174        }
    … …  
    192198         */
    193199        public function put_contents( $file, $contents, $mode = false ) {
    194                 $temp       = wp_tempnam( $file );
    195                 $temphandle = @fopen( $temp, 'w+' );
     200                $tempfile   = wp_tempnam( $file );
     201                $temphandle = @fopen( $tempfile, 'w+' );
     202
    196203                if ( ! $temphandle ) {
    197                         unlink( $temp );
     204                        unlink( $tempfile );
    198205                        return false;
    199206                }
    … …  
    203210
    204211                $bytes_written = fwrite( $temphandle, $contents );
     212
    205213                if ( false === $bytes_written || strlen( $contents ) != $bytes_written ) {
    206214                        fclose( $temphandle );
    207                         unlink( $temp );
     215                        unlink( $tempfile );
    208216
    209217                        reset_mbstring_encoding();
    … …  
    219227
    220228                fclose( $temphandle );
    221                 unlink( $temp );
     229                unlink( $tempfile );
    222230
    223231                $this->chmod( $file, $mode );
    … …  
    235243        public function cwd() {
    236244                $cwd = $this->ftp->pwd();
     245
    237246                if ( $cwd ) {
    238247                        $cwd = trailingslashit( $cwd );
    239248                }
     249
    240250                return $cwd;
    241251        }
    … …  
    279289                if ( $recursive && $this->is_dir( $file ) ) {
    280290                        $filelist = $this->dirlist( $file );
     291
    281292                        foreach ( (array) $filelist as $filename => $filemeta ) {
    282293                                $this->chmod( $file . '/' . $filename, $mode, $recursive );
    … …  
    298309        public function owner( $file ) {
    299310                $dir = $this->dirlist( $file );
     311
    300312                return $dir[ $file ]['owner'];
    301313        }
    … …  
    311323        public function getchmod( $file ) {
    312324                $dir = $this->dirlist( $file );
     325
    313326                return $dir[ $file ]['permsn'];
    314327        }
    … …  
    324337        public function group( $file ) {
    325338                $dir = $this->dirlist( $file );
     339
    326340                return $dir[ $file ]['group'];
    327341        }
    … …  
    346360
    347361                $content = $this->get_contents( $source );
     362
    348363                if ( false === $content ) {
    349364                        return false;
    … …  
    384399                        return false;
    385400                }
     401
    386402                if ( 'f' === $type || $this->is_file( $file ) ) {
    387403                        return $this->ftp->delete( $file );
    388404                }
     405
    389406                if ( ! $recursive ) {
    390407                        return $this->ftp->rmdir( $file );
    … …  
    425442                        return false;
    426443                }
     444
    427445                if ( $this->exists( $file ) ) {
    428446                        return true;
    429447                }
     448
    430449                return false;
    431450        }
    … …  
    441460        public function is_dir( $path ) {
    442461                $cwd = $this->cwd();
     462
    443463                if ( $this->chdir( $path ) ) {
    444464                        $this->chdir( $cwd );
    445465                        return true;
    446466                }
     467
    447468                return false;
    448469        }
    … …  
    542563        public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
    543564                $path = untrailingslashit( $path );
     565
    544566                if ( empty( $path ) ) {
    545567                        return false;
    … …  
    549571                        return false;
    550572                }
     573
    551574                if ( ! $chmod ) {
    552575                        $chmod = FS_CHMOD_DIR;
    553576                }
     577
    554578                $this->chmod( $path, $chmod );
     579
    555580                return true;
    556581        }
    … …  
    606631
    607632                $list = $this->ftp->dirlist( $path );
     633
    608634                if ( empty( $list ) && ! $this->exists( $path ) ) {
    609635
    … …  
    614640
    615641                $ret = array();
     642
    616643                foreach ( $list as $struc ) {
    617644
  • trunk/src/wp-admin/includes/class-wp-filesystem-ssh2.php

    r48031 r48089  
    133133                                )
    134134                        );
     135
    135136                        return false;
    136137                }
    … …  
    146147                                        )
    147148                                );
     149
    148150                                return false;
    149151                        }
    … …  
    158160                                        )
    159161                                );
     162
    160163                                return false;
    161164                        }
    … …  
    163166
    164167                $this->sftp_link = ssh2_sftp( $this->link );
     168
    165169                if ( ! $this->sftp_link ) {
    166170                        $this->errors->add(
    … …  
    172176                                )
    173177                        );
     178
    174179                        return false;
    175180                }
    … …  
    195200                        $path = '/./';
    196201                }
     202
    197203                return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' );
    198204        }
    … …  
    212218
    213219                $stream = ssh2_exec( $this->link, $command );
     220
    214221                if ( ! $stream ) {
    215222                        $this->errors->add(
    … …  
    233240                        }
    234241                }
     242
    235243                return false;
    236244        }
    … …  
    293301        public function cwd() {
    294302                $cwd = ssh2_sftp_realpath( $this->sftp_link, '.' );
     303
    295304                if ( $cwd ) {
    296305                        $cwd = trailingslashit( trim( $cwd ) );
    297306                }
     307
    298308                return $cwd;
    299309        }
    … …  
    326336                        return false;
    327337                }
     338
    328339                if ( ! $recursive || ! $this->is_dir( $file ) ) {
    329340                        return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
    330341                }
     342
    331343                return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
    332344        }
    … …  
    362374                        return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true );
    363375                }
     376
    364377                return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true );
    365378        }
    … …  
    380393                        return false;
    381394                }
     395
    382396                if ( ! $recursive || ! $this->is_dir( $file ) ) {
    383397                        return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
    384398                }
     399
    385400                return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
    386401        }
    … …  
    396411        public function owner( $file ) {
    397412                $owneruid = @fileowner( $this->sftp_path( $file ) );
     413
    398414                if ( ! $owneruid ) {
    399415                        return false;
    400416                }
     417
    401418                if ( ! function_exists( 'posix_getpwuid' ) ) {
    402419                        return $owneruid;
    403420                }
     421
    404422                $ownerarray = posix_getpwuid( $owneruid );
     423
    405424                if ( ! $ownerarray ) {
    406425                        return false;
    407426                }
     427
    408428                return $ownerarray['name'];
    409429        }
    … …  
    431451        public function group( $file ) {
    432452                $gid = @filegroup( $this->sftp_path( $file ) );
     453
    433454                if ( ! $gid ) {
    434455                        return false;
    435456                }
     457
    436458                if ( ! function_exists( 'posix_getgrgid' ) ) {
    437459                        return $gid;
    438460                }
     461
    439462                $grouparray = posix_getgrgid( $gid );
     463
    440464                if ( ! $grouparray ) {
    441465                        return false;
    442466                }
     467
    443468                return $grouparray['name'];
    444469        }
    … …  
    461486                        return false;
    462487                }
     488
    463489                $content = $this->get_contents( $source );
     490
    464491                if ( false === $content ) {
    465492                        return false;
    466493                }
     494
    467495                return $this->put_contents( $destination, $content, $mode );
    468496        }
    … …  
    509537                        return ssh2_sftp_unlink( $this->sftp_link, $file );
    510538                }
     539
    511540                if ( ! $recursive ) {
    512541                        return ssh2_sftp_rmdir( $this->sftp_link, $file );
    513542                }
     543
    514544                $filelist = $this->dirlist( $file );
     545
    515546                if ( is_array( $filelist ) ) {
    516547                        foreach ( $filelist as $filename => $fileinfo ) {
    … …  
    518549                        }
    519550                }
     551
    520552                return ssh2_sftp_rmdir( $this->sftp_link, $file );
    521553        }
    … …  
    651683        public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
    652684                $path = untrailingslashit( $path );
     685
    653686                if ( empty( $path ) ) {
    654687                        return false;
    … …  
    658691                        $chmod = FS_CHMOD_DIR;
    659692                }
     693
    660694                if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) {
    661695                        return false;
    662696                }
     697
    663698                if ( $chown ) {
    664699                        $this->chown( $path, $chown );
    665700                }
     701
    666702                if ( $chgrp ) {
    667703                        $this->chgrp( $path, $chgrp );
    668704                }
     705
    669706                return true;
    670707        }
    … …  
    765802                        $ret[ $struc['name'] ] = $struc;
    766803                }
     804
    767805                $dir->close();
    768806                unset( $dir );
     807
    769808                return $ret;
    770809        }
Note: See TracChangeset for help on using the changeset viewer.