Make WordPress Core


Ignore:
Timestamp:
04/13/2009 04:11:02 PM (17 years ago)
Author:
ryan
Message:

WPFS cleanups. Props DD32. fixes #9525

File:
1 edited

Legend:

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

    r10051 r10919  
    1515 * @uses WP_Filesystem_Base Extends class
    1616 */
    17 class WP_Filesystem_Direct  extends WP_Filesystem_Base {
     17class WP_Filesystem_Direct extends WP_Filesystem_Base {
    1818    var $permission = null;
    19     var $errors = array();
     19    var $errors = null;
    2020    function WP_Filesystem_Direct($arg) {
    2121        $this->method = 'direct';
     
    5050    }
    5151    function chgrp($file, $group, $recursive = false) {
    52         if( ! $this->exists($file) )
    53             return false;
    54         if( ! $recursive )
     52        if ( ! $this->exists($file) )
     53            return false;
     54        if ( ! $recursive )
    5555            return @chgrp($file, $group);
    56         if( ! $this->is_dir($file) )
     56        if ( ! $this->is_dir($file) )
    5757            return @chgrp($file, $group);
    5858        //Is a directory, and we want recursive
    5959        $file = trailingslashit($file);
    6060        $filelist = $this->dirlist($file);
    61         foreach($filelist as $filename)
     61        foreach ($filelist as $filename)
    6262            $this->chgrp($file . $filename, $group, $recursive);
    6363
     
    6565    }
    6666    function chmod($file, $mode = false, $recursive = false) {
    67         if( ! $mode )
     67        if ( ! $mode )
    6868            $mode = $this->permission;
    69         if( ! $this->exists($file) )
    70             return false;
    71         if( ! $recursive )
     69        if ( ! $this->exists($file) )
     70            return false;
     71        if ( ! $recursive )
    7272            return @chmod($file,$mode);
    73         if( ! $this->is_dir($file) )
     73        if ( ! $this->is_dir($file) )
    7474            return @chmod($file, $mode);
    7575        //Is a directory, and we want recursive
    7676        $file = trailingslashit($file);
    7777        $filelist = $this->dirlist($file);
    78         foreach($filelist as $filename)
     78        foreach ($filelist as $filename)
    7979            $this->chmod($file . $filename, $mode, $recursive);
    8080
     
    8282    }
    8383    function chown($file, $owner, $recursive = false) {
    84         if( ! $this->exists($file) )
    85             return false;
    86         if( ! $recursive )
     84        if ( ! $this->exists($file) )
     85            return false;
     86        if ( ! $recursive )
    8787            return @chown($file, $owner);
    88         if( ! $this->is_dir($file) )
     88        if ( ! $this->is_dir($file) )
    8989            return @chown($file, $owner);
    9090        //Is a directory, and we want recursive
    9191        $filelist = $this->dirlist($file);
    92         foreach($filelist as $filename){
     92        foreach ($filelist as $filename){
    9393            $this->chown($file . '/' . $filename, $owner, $recursive);
    9494        }
     
    9797    function owner($file) {
    9898        $owneruid = @fileowner($file);
    99         if( ! $owneruid )
    100             return false;
    101         if( ! function_exists('posix_getpwuid') )
     99        if ( ! $owneruid )
     100            return false;
     101        if ( ! function_exists('posix_getpwuid') )
    102102            return $owneruid;
    103103        $ownerarray = posix_getpwuid($owneruid);
     
    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);
    111         if( ! $gid )
    112             return false;
    113         if( ! function_exists('posix_getgrgid') )
     111        if ( ! $gid )
     112            return false;
     113        if ( ! function_exists('posix_getgrgid') )
    114114            return $gid;
    115115        $grouparray = posix_getgrgid($gid);
     
    118118
    119119    function copy($source, $destination, $overwrite = false) {
    120         if( ! $overwrite && $this->exists($destination) )
     120        if ( ! $overwrite && $this->exists($destination) )
    121121            return false;
    122122        return copy($source, $destination);
     
    125125    function move($source, $destination, $overwrite = false) {
    126126        //Possible to use rename()?
    127         if( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
     127        if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
    128128            $this->delete($source);
    129129            return true;
     
    134134
    135135    function delete($file, $recursive = false) {
     136        if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
     137            return false;
    136138        $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
    137139
    138         if( $this->is_file($file) )
     140        if ( $this->is_file($file) )
    139141            return @unlink($file);
    140         if( ! $recursive && $this->is_dir($file) )
     142        if ( ! $recursive && $this->is_dir($file) )
    141143            return @rmdir($file);
    142144
     
    146148
    147149        $retval = true;
    148         if( is_array($filelist) ) //false if no files, So check first.
    149             foreach($filelist as $filename => $fileinfo)
    150                 if( ! $this->delete($file . $filename, $recursive) )
     150        if ( is_array($filelist) ) //false if no files, So check first.
     151            foreach ($filelist as $filename => $fileinfo)
     152                if ( ! $this->delete($file . $filename, $recursive) )
    151153                    $retval = false;
    152154
    153         if( ! @rmdir($file) )
    154             return false;
     155        if ( file_exists($file) && ! @rmdir($file) )
     156            $retval = false;
    155157        return $retval;
    156158    }
     
    188190
    189191    function touch($file, $time = 0, $atime = 0){
    190         if($time == 0)
     192        if ($time == 0)
    191193            $time = time();
    192         if($atime == 0)
     194        if ($atime == 0)
    193195            $atime = time();
    194196        return @touch($file, $time, $atime);
     
    196198
    197199    function mkdir($path, $chmod = false, $chown = false, $chgrp = false){
    198         if( ! $chmod)
     200        if ( ! $chmod)
    199201            $chmod = $this->permission;
    200202
    201         if( ! @mkdir($path, $chmod) )
    202             return false;
    203         if( $chown )
     203        if ( ! @mkdir($path, $chmod) )
     204            return false;
     205        if ( $chown )
    204206            $this->chown($path, $chown);
    205         if( $chgrp )
     207        if ( $chgrp )
    206208            $this->chgrp($path, $chgrp);
    207209        return true;
     
    210212    function rmdir($path, $recursive = false) {
    211213        //Currently unused and untested, Use delete() instead.
    212         if( ! $recursive )
     214        if ( ! $recursive )
    213215            return @rmdir($path);
    214216        //recursive:
    215217        $filelist = $this->dirlist($path);
    216         foreach($filelist as $filename => $det) {
     218        foreach ($filelist as $filename => $det) {
    217219            if ( '/' == substr($filename, -1, 1) )
    218220                $this->rmdir($path . '/' . $filename, $recursive);
     
    223225
    224226    function dirlist($path, $incdot = false, $recursive = false) {
    225         if( $this->is_file($path) ) {
     227        if ( $this->is_file($path) ) {
    226228            $limitFile = basename($path);
    227229            $path = dirname($path);
     
    229231            $limitFile = false;
    230232        }
    231         if( ! $this->is_dir($path) )
     233        if ( ! $this->is_dir($path) )
    232234            return false;
    233235
     
    240242            $struc['name'] = $entry;
    241243
    242             if( '.' == $struc['name'] || '..' == $struc['name'] )
     244            if ( '.' == $struc['name'] || '..' == $struc['name'] )
    243245                continue; //Do not care about these folders.
    244             if( '.' == $struc['name'][0] && !$incdot)
     246            if ( '.' == $struc['name'][0] && !$incdot)
    245247                continue;
    246             if( $limitFile && $struc['name'] != $limitFile)
     248            if ( $limitFile && $struc['name'] != $limitFile)
    247249                continue;
    248250
     
    259261
    260262            if ( 'd' == $struc['type'] ) {
    261                 if( $recursive )
     263                if ( $recursive )
    262264                    $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
    263265                else
Note: See TracChangeset for help on using the changeset viewer.