Make WordPress Core

Changeset 34738


Ignore:
Timestamp:
10/01/2015 05:39:44 AM (10 years ago)
Author:
dd32
Message:

Updates: SSH2 Transport: Use a work around to avoid a bug where PHP's SSH2 extension fails to list the contents of the / directory.
This fixes issues where SSH2 with chrooted environments runs into a Unable to locate WordPress Content directory (wp-content). error.

The workaround is to simply list the contents of the /./ directory instead of /.

Fixes #33919

File:
1 edited

Legend:

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

    r33984 r34738  
    137137
    138138    /**
     139     * Gets the ssh2.sftp PHP stream wrapper path to open for the given file.
     140     *
     141     * This method also works around a PHP bug where the root directory (/) cannot
     142     * be opened by PHP functions, causing a false failure. In order to work around
     143     * this, the path is converted to /./ which is semantically the same as /
     144     * See https://bugs.php.net/bug.php?id=64169 for more details.
     145     *
     146     * @access public
     147     *
     148     * @since 4.4
     149     *
     150     * @param string $path The File/Directory path on the remote server to return
     151     * @return string The ssh2.sftp:// wrapped path to use.
     152     */
     153    public function sftp_path( $path ) {
     154        if ( '/' === $path ) {
     155            $path = '/./';
     156        }
     157        return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' );
     158    }
     159
     160    /**
    139161     * @access public
    140162     *
     
    170192     */
    171193    public function get_contents( $file ) {
    172         $file = ltrim($file, '/');
    173         return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file);
     194        return file_get_contents( $this->sftp_path( $file ) );
    174195    }
    175196
     
    181202     */
    182203    public function get_contents_array($file) {
    183         $file = ltrim($file, '/');
    184         return file('ssh2.sftp://' . $this->sftp_link . '/' . $file);
     204        return file( $this->sftp_path( $file ) );
    185205    }
    186206
     
    194214     */
    195215    public function put_contents($file, $contents, $mode = false ) {
    196         $ret = file_put_contents( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ), $contents );
     216        $ret = file_put_contents( $this->sftp_path( $file ), $contents );
    197217
    198218        if ( $ret !== strlen( $contents ) )
     
    295315     */
    296316    public function owner($file) {
    297         $owneruid = @fileowner('ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/'));
     317        $owneruid = @fileowner( $this->sftp_path( $file ) );
    298318        if ( ! $owneruid )
    299319            return false;
     
    311331     */
    312332    public function getchmod($file) {
    313         return substr( decoct( @fileperms( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ) ) ), -3 );
     333        return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 );
    314334    }
    315335
     
    321341     */
    322342    public function group($file) {
    323         $gid = @filegroup('ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/'));
     343        $gid = @filegroup( $this->sftp_path( $file ) );
    324344        if ( ! $gid )
    325345            return false;
     
    389409     */
    390410    public function exists($file) {
    391         $file = ltrim($file, '/');
    392         return file_exists('ssh2.sftp://' . $this->sftp_link . '/' . $file);
     411        return file_exists( $this->sftp_path( $file ) );
    393412    }
    394413
     
    400419     */
    401420    public function is_file($file) {
    402         $file = ltrim($file, '/');
    403         return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file);
     421        return is_file( $this->sftp_path( $file ) );
    404422    }
    405423
     
    411429     */
    412430    public function is_dir($path) {
    413         $path = ltrim($path, '/');
    414         return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path);
     431        return is_dir( $this->sftp_path( $path ) );
    415432    }
    416433
     
    422439     */
    423440    public function is_readable($file) {
    424         $file = ltrim($file, '/');
    425         return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file);
     441        return is_readable( $this->sftp_path( $file ) );
    426442    }
    427443
     
    444460     */
    445461    public function atime($file) {
    446         $file = ltrim($file, '/');
    447         return fileatime('ssh2.sftp://' . $this->sftp_link . '/' . $file);
     462        return fileatime( $this->sftp_path( $file ) );
    448463    }
    449464
     
    455470     */
    456471    public function mtime($file) {
    457         $file = ltrim($file, '/');
    458         return filemtime('ssh2.sftp://' . $this->sftp_link . '/' . $file);
     472        return filemtime( $this->sftp_path( $file ) );
    459473    }
    460474
     
    466480     */
    467481    public function size($file) {
    468         $file = ltrim($file, '/');
    469         return filesize('ssh2.sftp://' . $this->sftp_link . '/' . $file);
     482        return filesize( $this->sftp_path( $file ) );
    470483    }
    471484
     
    537550
    538551        $ret = array();
    539         $dir = @dir('ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') );
     552        $dir = @dir( $this->sftp_path( $path ) );
    540553
    541554        if ( ! $dir )
Note: See TracChangeset for help on using the changeset viewer.