WordPress.org

Make WordPress Core

Changeset 17525


Ignore:
Timestamp:
03/22/11 00:04:15 (7 years ago)
Author:
dd32
Message:

Optimisations to WP_Filesystem; Pass known information to called functions. Props aldenta (John Ford) for investigation and patch. See #10913

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

Legend:

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

    r15590 r17525  
    194194    } 
    195195 
    196     function copy($source, $destination, $overwrite = false) { 
     196    function copy($source, $destination, $overwrite = false, $mode = false) { 
    197197        if ( ! $overwrite && $this->exists($destination) ) 
    198198            return false; 
    199199 
    200         return copy($source, $destination); 
     200        $rtval = copy($source, $destination); 
     201        if ( $mode ) 
     202            $this->chmod($destination, $mode); 
     203        return $rtval; 
    201204    } 
    202205 
     
    217220    } 
    218221 
    219     function delete($file, $recursive = false) { 
     222    function delete($file, $recursive = false, $type = false) { 
    220223        if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. 
    221224            return false; 
    222225        $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise 
    223226 
    224         if ( $this->is_file($file) ) 
     227        if ( 'f' == $type || $this->is_file($file) ) 
    225228            return @unlink($file); 
    226229        if ( ! $recursive && $this->is_dir($file) ) 
     
    234237        if ( is_array($filelist) ) //false if no files, So check first. 
    235238            foreach ($filelist as $filename => $fileinfo) 
    236                 if ( ! $this->delete($file . $filename, $recursive) ) 
     239                if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) ) 
    237240                    $retval = false; 
    238241 
  • trunk/wp-admin/includes/class-wp-filesystem-ftpext.php

    r15086 r17525  
    184184        return $dir[$file]['group']; 
    185185    } 
    186     function copy($source, $destination, $overwrite = false ) { 
     186    function copy($source, $destination, $overwrite = false, $mode = false) { 
    187187        if ( ! $overwrite && $this->exists($destination) ) 
    188188            return false; 
     
    190190        if ( false === $content) 
    191191            return false; 
    192         return $this->put_contents($destination, $content); 
     192        return $this->put_contents($destination, $content, $mode); 
    193193    } 
    194194    function move($source, $destination, $overwrite = false) { 
     
    196196    } 
    197197 
    198     function delete($file, $recursive = false ) { 
     198    function delete($file, $recursive = false, $type = false) { 
    199199        if ( empty($file) ) 
    200200            return false; 
    201         if ( $this->is_file($file) ) 
     201        if ( 'f' == $type || $this->is_file($file) ) 
    202202            return @ftp_delete($this->link, $file); 
    203203        if ( !$recursive ) 
     
    207207        if ( !empty($filelist) ) 
    208208            foreach ( $filelist as $delete_file ) 
    209                 $this->delete( trailingslashit($file) . $delete_file['name'], $recursive); 
     209                $this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] ); 
    210210        return @ftp_rmdir($this->link, $file); 
    211211    } 
  • trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r13770 r17525  
    194194    } 
    195195 
    196     function copy($source, $destination, $overwrite = false ) { 
     196    function copy($source, $destination, $overwrite = false, $mode = false) { 
    197197        if ( ! $overwrite && $this->exists($destination) ) 
    198198            return false; 
     
    202202            return false; 
    203203 
    204         return $this->put_contents($destination, $content); 
     204        return $this->put_contents($destination, $content, $mode); 
    205205    } 
    206206 
     
    209209    } 
    210210 
    211     function delete($file, $recursive = false ) { 
     211    function delete($file, $recursive = false, $type = false) { 
    212212        if ( empty($file) ) 
    213213            return false; 
    214         if ( $this->is_file($file) ) 
     214        if ( 'f' == $type || $this->is_file($file) ) 
    215215            return $this->ftp->delete($file); 
    216216        if ( !$recursive ) 
  • trunk/wp-admin/includes/class-wp-filesystem-ssh2.php

    r13770 r17525  
    239239    } 
    240240 
    241     function copy($source, $destination, $overwrite = false ) { 
     241    function copy($source, $destination, $overwrite = false, $mode = false) { 
    242242        if ( ! $overwrite && $this->exists($destination) ) 
    243243            return false; 
     
    245245        if ( false === $content) 
    246246            return false; 
    247         return $this->put_contents($destination, $content); 
     247        return $this->put_contents($destination, $content, $mode); 
    248248    } 
    249249 
     
    252252    } 
    253253 
    254     function delete($file, $recursive = false) { 
    255         if ( $this->is_file($file) ) 
     254    function delete($file, $recursive = false, $type = false) { 
     255        if ( 'f' == $type || $this->is_file($file) ) 
    256256            return ssh2_sftp_unlink($this->sftp_link, $file); 
    257257        if ( ! $recursive ) 
     
    260260        if ( is_array($filelist) ) { 
    261261            foreach ( $filelist as $filename => $fileinfo) { 
    262                 $this->delete($file . '/' . $filename, $recursive); 
     262                $this->delete($file . '/' . $filename, $recursive, $fileinfo['type']); 
    263263            } 
    264264        } 
  • trunk/wp-admin/includes/file.php

    r17200 r17525  
    8181    $siteurl = get_option( 'siteurl' ); 
    8282    if ( $home != '' && $home != $siteurl ) { 
    83             $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */ 
    84             $pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home); 
    85             $home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos); 
     83        $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */ 
     84        $pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home); 
     85        $home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos); 
    8686        $home_path = trailingslashit( $home_path ); 
    8787    } else { 
     
    774774    foreach ( (array) $dirlist as $filename => $fileinfo ) { 
    775775        if ( 'f' == $fileinfo['type'] ) { 
    776             if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) { 
     776            if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) { 
    777777                // If copy failed, chmod file to 0644 and try again. 
    778778                $wp_filesystem->chmod($to . $filename, 0644); 
    779                 if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) 
     779                if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) 
    780780                    return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename); 
    781781            } 
    782             $wp_filesystem->chmod($to . $filename, FS_CHMOD_FILE); 
    783782        } elseif ( 'd' == $fileinfo['type'] ) { 
    784783            if ( !$wp_filesystem->is_dir($to . $filename) ) { 
Note: See TracChangeset for help on using the changeset viewer.