Changeset 10919 for trunk/wp-admin/includes/class-wp-filesystem-direct.php
- Timestamp:
- 04/13/2009 04:11:02 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-direct.php
r10051 r10919 15 15 * @uses WP_Filesystem_Base Extends class 16 16 */ 17 class WP_Filesystem_Direct extends WP_Filesystem_Base {17 class WP_Filesystem_Direct extends WP_Filesystem_Base { 18 18 var $permission = null; 19 var $errors = array();19 var $errors = null; 20 20 function WP_Filesystem_Direct($arg) { 21 21 $this->method = 'direct'; … … 50 50 } 51 51 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 ) 55 55 return @chgrp($file, $group); 56 if ( ! $this->is_dir($file) )56 if ( ! $this->is_dir($file) ) 57 57 return @chgrp($file, $group); 58 58 //Is a directory, and we want recursive 59 59 $file = trailingslashit($file); 60 60 $filelist = $this->dirlist($file); 61 foreach ($filelist as $filename)61 foreach ($filelist as $filename) 62 62 $this->chgrp($file . $filename, $group, $recursive); 63 63 … … 65 65 } 66 66 function chmod($file, $mode = false, $recursive = false) { 67 if ( ! $mode )67 if ( ! $mode ) 68 68 $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 ) 72 72 return @chmod($file,$mode); 73 if ( ! $this->is_dir($file) )73 if ( ! $this->is_dir($file) ) 74 74 return @chmod($file, $mode); 75 75 //Is a directory, and we want recursive 76 76 $file = trailingslashit($file); 77 77 $filelist = $this->dirlist($file); 78 foreach ($filelist as $filename)78 foreach ($filelist as $filename) 79 79 $this->chmod($file . $filename, $mode, $recursive); 80 80 … … 82 82 } 83 83 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 ) 87 87 return @chown($file, $owner); 88 if ( ! $this->is_dir($file) )88 if ( ! $this->is_dir($file) ) 89 89 return @chown($file, $owner); 90 90 //Is a directory, and we want recursive 91 91 $filelist = $this->dirlist($file); 92 foreach ($filelist as $filename){92 foreach ($filelist as $filename){ 93 93 $this->chown($file . '/' . $filename, $owner, $recursive); 94 94 } … … 97 97 function owner($file) { 98 98 $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') ) 102 102 return $owneruid; 103 103 $ownerarray = posix_getpwuid($owneruid); … … 105 105 } 106 106 function getchmod($file) { 107 return @fileperms($file);107 return substr(decoct(@fileperms($file)),3); 108 108 } 109 109 function group($file) { 110 110 $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') ) 114 114 return $gid; 115 115 $grouparray = posix_getgrgid($gid); … … 118 118 119 119 function copy($source, $destination, $overwrite = false) { 120 if ( ! $overwrite && $this->exists($destination) )120 if ( ! $overwrite && $this->exists($destination) ) 121 121 return false; 122 122 return copy($source, $destination); … … 125 125 function move($source, $destination, $overwrite = false) { 126 126 //Possible to use rename()? 127 if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){127 if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){ 128 128 $this->delete($source); 129 129 return true; … … 134 134 135 135 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; 136 138 $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise 137 139 138 if ( $this->is_file($file) )140 if ( $this->is_file($file) ) 139 141 return @unlink($file); 140 if ( ! $recursive && $this->is_dir($file) )142 if ( ! $recursive && $this->is_dir($file) ) 141 143 return @rmdir($file); 142 144 … … 146 148 147 149 $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) ) 151 153 $retval = false; 152 154 153 if (! @rmdir($file) )154 returnfalse;155 if ( file_exists($file) && ! @rmdir($file) ) 156 $retval = false; 155 157 return $retval; 156 158 } … … 188 190 189 191 function touch($file, $time = 0, $atime = 0){ 190 if ($time == 0)192 if ($time == 0) 191 193 $time = time(); 192 if ($atime == 0)194 if ($atime == 0) 193 195 $atime = time(); 194 196 return @touch($file, $time, $atime); … … 196 198 197 199 function mkdir($path, $chmod = false, $chown = false, $chgrp = false){ 198 if ( ! $chmod)200 if ( ! $chmod) 199 201 $chmod = $this->permission; 200 202 201 if ( ! @mkdir($path, $chmod) )202 return false; 203 if ( $chown )203 if ( ! @mkdir($path, $chmod) ) 204 return false; 205 if ( $chown ) 204 206 $this->chown($path, $chown); 205 if ( $chgrp )207 if ( $chgrp ) 206 208 $this->chgrp($path, $chgrp); 207 209 return true; … … 210 212 function rmdir($path, $recursive = false) { 211 213 //Currently unused and untested, Use delete() instead. 212 if ( ! $recursive )214 if ( ! $recursive ) 213 215 return @rmdir($path); 214 216 //recursive: 215 217 $filelist = $this->dirlist($path); 216 foreach ($filelist as $filename => $det) {218 foreach ($filelist as $filename => $det) { 217 219 if ( '/' == substr($filename, -1, 1) ) 218 220 $this->rmdir($path . '/' . $filename, $recursive); … … 223 225 224 226 function dirlist($path, $incdot = false, $recursive = false) { 225 if ( $this->is_file($path) ) {227 if ( $this->is_file($path) ) { 226 228 $limitFile = basename($path); 227 229 $path = dirname($path); … … 229 231 $limitFile = false; 230 232 } 231 if ( ! $this->is_dir($path) )233 if ( ! $this->is_dir($path) ) 232 234 return false; 233 235 … … 240 242 $struc['name'] = $entry; 241 243 242 if ( '.' == $struc['name'] || '..' == $struc['name'] )244 if ( '.' == $struc['name'] || '..' == $struc['name'] ) 243 245 continue; //Do not care about these folders. 244 if ( '.' == $struc['name'][0] && !$incdot)246 if ( '.' == $struc['name'][0] && !$incdot) 245 247 continue; 246 if ( $limitFile && $struc['name'] != $limitFile)248 if ( $limitFile && $struc['name'] != $limitFile) 247 249 continue; 248 250 … … 259 261 260 262 if ( 'd' == $struc['type'] ) { 261 if ( $recursive )263 if ( $recursive ) 262 264 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 263 265 else
Note: See TracChangeset
for help on using the changeset viewer.