Ticket #8478: 8478.diff

File 8478.diff, 7.4 KB (added by DD32, 3 years ago)
  • wp-admin/includes/class-wp-filesystem-direct.php

     
    104104                return $ownerarray['name']; 
    105105        } 
    106106        function getchmod($file) { 
    107                 return @fileperms($file); 
     107                return substr(decoct(@fileperms($file)),3); 
    108108        } 
    109109        function group($file) { 
    110110                $gid = @filegroup($file); 
  • wp-admin/includes/class-wp-filesystem-ftpext.php

     
    169169        } 
    170170        function getchmod($file) { 
    171171                $dir = $this->dirlist($file); 
    172                 return $dir[$file]['permsn']; 
     172                return $this->getnumchmodfromh( $dir[basename($file)]['perms'] ); 
    173173        } 
    174174        function group($file) { 
    175175                $dir = $this->dirlist($file); 
     
    321321        } 
    322322 
    323323        function dirlist($path = '.', $incdot = false, $recursive = false) { 
    324                 if( $this->is_file($path) ) { 
    325                         $limitFile = basename($path); 
    326                         $path = dirname($path) . '/'; 
     324 
     325                if ( substr($path, -1) !== '/') { 
     326                        $limit = basename($path); 
     327                        $path = trailingslashit(dirname($path)); 
    327328                } else { 
    328                         $limitFile = false; 
     329                        $limit = false; 
    329330                } 
    330331 
    331332                $list = @ftp_rawlist($this->link, '-a ' . $path, false); 
     
    339340                        if ( empty($entry) ) 
    340341                                continue; 
    341342 
    342                         if ( '.' == $entry["name"] || '..' == $entry["name"] ) 
     343                        if ( '.' == $entry['name'] || '..' == $entry['name'] ) 
    343344                                continue; 
    344345 
     346                        if ( $limit && $entry['name'] != $limit ) 
     347                                continue; 
     348 
    345349                        $dirlist[ $entry['name'] ] = $entry; 
    346350                } 
    347351 
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php

     
    186186 
    187187        function getchmod($file) { 
    188188                $dir = $this->dirlist($file); 
    189                 return $dir[$file]['permsn']; 
     189                return $this->getnumchmodfromh( $dir[basename($file)]['perms'] ); 
    190190        } 
    191191 
    192192        function group($file) { 
     
    281281        } 
    282282 
    283283        function dirlist($path = '.', $incdot = false, $recursive = false ) { 
    284                 if( $this->is_file($path) ) { 
    285                         $limitFile = basename($path); 
    286                         $path = dirname($path) . '/'; 
     284 
     285                if ( substr($path, -1) !== '/') { 
     286                        $limit = basename($path); 
     287                        $path = trailingslashit(dirname($path)); 
    287288                } else { 
    288                         $limitFile = false; 
     289                        $limit = false; 
    289290                } 
    290291 
    291292                $list = $this->ftp->dirlist($path); 
    292293                if( ! $list ) 
    293294                        return false; 
     295 
    294296                if( empty($list) ) 
    295297                        return array(); 
    296298 
    297299                $ret = array(); 
    298300                foreach ( $list as $struc ) { 
     301                        if ( $limit && $struc['name'] != $limit ) 
     302                                continue; 
    299303 
    300304                        if ( 'd' == $struc['type'] ) { 
    301305                                $struc['files'] = array(); 
  • wp-admin/includes/class-wp-filesystem-ssh2.php

     
    270291        function getchmod($file) { 
    271292                $this->debug("getchmod();"); 
    272293                $dir = $this->dirlist($file); 
    273                 return $dir[$file]['permsn']; 
     294                return $this->getnumchmodfromh( $dir[basename($file)]['perms'] ); 
    274295        } 
    275296 
    276297        function group($file) { 
  • wp-admin/includes/file.php

     
    498498                if ( $fs->is_dir($tmppath) ) { //Found the highest folder that exists, Create from here(ie +1) 
    499499                        for ( $i = $i + 1; $i <= count($path); $i++ ) { 
    500500                                $tmppath = implode('/', array_slice($path, 0, $i) ); 
    501                                 if ( ! $fs->mkdir($tmppath, 0755) ) 
     501                                if ( ! $fs->mkdir($tmppath, FS_CHMOD_DIR) ) 
    502502                                        return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath); 
    503503                        } 
    504504                        break; //Exit main for loop 
     
    516516                        if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here 
    517517                                for ( $i = $i + 1; $i <= count($path); $i++ ) { //< count() no file component please. 
    518518                                        $tmppath = $to . implode('/', array_slice($path, 0, $i) ); 
    519                                         if ( ! $fs->is_dir($tmppath) && ! $fs->mkdir($tmppath, 0755) ) 
     519                                        if ( ! $fs->is_dir($tmppath) && ! $fs->mkdir($tmppath, FS_CHMOD_DIR) ) 
    520520                                                return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath); 
    521521                                } 
    522522                                break; //Exit main for loop 
     
    527527                if ( ! $file['folder'] ) { 
    528528                        if ( !$fs->put_contents( $to . $file['filename'], $file['content']) ) 
    529529                                return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']); 
    530                         $fs->chmod($to . $file['filename'], 0644); 
     530                        $fs->chmod($to . $file['filename'], FS_CHMOD_FILE); 
    531531                } 
    532532        } 
    533533        return true; 
     
    558558                                if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) 
    559559                                        return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename); 
    560560                        } 
    561                         $wp_filesystem->chmod($to . $filename, 0644); 
     561                        $wp_filesystem->chmod($to . $filename, FS_CHMOD_FILE); 
    562562                } elseif ( 'd' == $fileinfo['type'] ) { 
    563563                        if ( !$wp_filesystem->is_dir($to . $filename) ) { 
    564                                 if ( !$wp_filesystem->mkdir($to . $filename, 0755) ) 
     564                                if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) ) 
    565565                                        return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename); 
    566566                        } 
    567567                        $result = copy_dir($from . $filename, $to . $filename); 
     
    604604        if ( !$wp_filesystem->connect() ) 
    605605                return false; //There was an erorr connecting to the server. 
    606606 
     607        //Set the Permission constants if not allready set. 
     608        if ( ! defined('FS_CHMOD_DIR') || ! defined('FS_CHMOD_FILE') ) { 
     609                $path = $wp_filesystem->abspath(); 
     610 
     611                if ( ! defined('FS_CHMOD_DIR') ) 
     612                        define('FS_CHMOD_DIR', octdec($wp_filesystem->getchmod($path . 'wp-includes')) ); 
     613                if ( ! defined('FS_CHMOD_FILE') ) 
     614                        define('FS_CHMOD_FILE', octdec($wp_filesystem->getchmod($path . 'wp-settings.php')) ); 
     615        } 
     616 
    607617        return true; 
    608618} 
    609619 
  • wp-admin/includes/update-core.php

     
    227227        $maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; 
    228228        $maintenance_file = $to . '.maintenance'; 
    229229        $wp_filesystem->delete($maintenance_file); 
    230         $wp_filesystem->put_contents($maintenance_file, $maintenance_string, 0644); 
     230        $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE); 
    231231 
    232232        // Copy new versions of WP files into place. 
    233233        $result = copy_dir($from . '/wordpress', $to); 
  • wp-admin/includes/update.php

     
    468468                $wp_filesystem->delete($working_dir, true); 
    469469                return new WP_Error('copy_failed', __('Could not copy files')); 
    470470        } 
    471         $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', 0644); 
     471        $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); 
    472472 
    473473        require(ABSPATH . 'wp-admin/includes/update-core.php'); 
    474474