WordPress.org

Make WordPress Core

Changeset 12723


Ignore:
Timestamp:
01/14/2010 09:23:53 AM (10 years ago)
Author:
dd32
Message:

Standardise WP_Filesystem_*::put_contents() arguments to support chmod reliably across all transports. Fixes #10889

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

Legend:

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

    r11934 r12723  
    5555     * Write a string to a file
    5656     *
    57      * @param $file string Path to the file where to write the data.
     57     * @param $file string Remote path to the file where to write the data.
    5858     * @param $contents string The data to write.
    5959     * @param $mode int (optional) The file permissions as octal number, usually 0644.
    60      * @param $type string (optional) Specifies additional type of access you require to the file.
    6160     * @return bool False upon failure.
    6261     */
    63     function put_contents($file, $contents, $mode = false, $type = '') {
    64         if ( ! ($fp = @fopen($file, 'w' . $type)) )
     62    function put_contents($file, $contents, $mode = false ) {
     63        if ( ! ($fp = @fopen($file, 'w')) )
    6564            return false;
    6665        @fwrite($fp, $contents);
  • trunk/wp-admin/includes/class-wp-filesystem-ftpext.php

    r12369 r12723  
    112112        return explode("\n", $this->get_contents($file));
    113113    }
    114     function put_contents($file, $contents, $type = '' ) {
    115         if ( empty($type) )
    116             $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
    117 
     114   
     115    function put_contents($file, $contents, $mode = false ) {
    118116        $temp = tmpfile();
    119117        if ( ! $temp )
     
    123121        fseek($temp, 0); //Skip back to the start of the file being written to
    124122
     123        $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
    125124        $ret = @ftp_fput($this->link, $file, $temp, $type);
    126125
    127126        fclose($temp);
     127
     128        $this->chmod($file, $mode);
     129
    128130        return $ret;
    129131    }
  • trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r12104 r12723  
    116116    }
    117117
    118     function put_contents($file, $contents, $type = '' ) {
    119         if ( empty($type) )
    120             $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
    121 
    122         $this->ftp->SetType($type);
    123 
     118    function put_contents($file, $contents, $mode = false ) {
    124119        $temp = wp_tempnam( $file );
    125         if ( ! $temphandle = fopen($temp, 'w+') ) {
     120        if ( ! $temphandle = @fopen($temp, 'w+') ) {
    126121            unlink($temp);
    127122            return false;
     
    131126        fseek($temphandle, 0); //Skip back to the start of the file being written to
    132127
     128        $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
     129        $this->ftp->SetType($type);
     130
    133131        $ret = $this->ftp->fput($file, $temphandle);
    134132
    135133        fclose($temphandle);
    136134        unlink($temp);
     135
     136        $this->chmod($file, $mode);
     137
    137138        return $ret;
    138139    }
  • trunk/wp-admin/includes/class-wp-filesystem-ssh2.php

    r11934 r12723  
    161161    }
    162162
    163     function put_contents($file, $contents, $type = '' ) {
    164         $file = ltrim($file, '/');
    165         return false !== file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
     163    function put_contents($file, $contents, $mode = false ) {
     164        $file = ltrim($file, '/');
     165        $ret = file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
     166
     167        $this->chmod($file, $mode);
     168
     169        return false !== $ret;
    166170    }
    167171
  • trunk/wp-admin/includes/file.php

    r12544 r12723  
    551551        // We've made sure the folders are there, so let's extract the file now:
    552552        if ( ! $file['folder'] ) {
    553             if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
     553            if ( !$fs->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )
    554554                return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
    555             $fs->chmod($to . $file['filename'], FS_CHMOD_FILE);
    556555        }
    557556    }
Note: See TracChangeset for help on using the changeset viewer.