Ticket #10170: 10170.2.patch
File 10170.2.patch, 6.1 KB (added by , 15 years ago) |
---|
-
wp-admin/includes/class-wp-filesystem-direct.php
17 17 class WP_Filesystem_Direct extends WP_Filesystem_Base { 18 18 var $permission = null; 19 19 var $errors = null; 20 /** 21 * constructor 22 * 23 * @param $arg mixed ingored argument 24 */ 20 25 function WP_Filesystem_Direct($arg) { 21 26 $this->method = 'direct'; 22 27 $this->errors = new WP_Error(); 23 $this->permission = umask();28 $this->permission = 0777; 24 29 } 30 /** 31 * connect filesystem. 32 * 33 * @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct). 34 */ 25 35 function connect() { 26 36 return true; 27 37 } 38 /** 39 * default permission setter 40 * 41 * @param $perm int default permission mask (octal). 42 * @return void 43 */ 28 44 function setDefaultPermissions($perm) { 29 45 $this->permission = $perm; 30 46 } 47 /** 48 * Reads entire file into a string 49 * 50 * @param $file string Name of the file to read. 51 * @return string|bool The function returns the read data or false on failure. 52 */ 31 53 function get_contents($file) { 32 54 return @file_get_contents($file); 33 55 } 56 /** 57 * Reads entire file into an array 58 * 59 * @param $file string Path to the file. 60 * @return array|bool the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. Upon failure, get_contents_array returns false. 61 */ 34 62 function get_contents_array($file) { 35 63 return @file($file); 36 64 } 65 /** 66 * Write a string to a file 67 * 68 * @param $file string Path to the file where to write the data. 69 * @param $contents string The data to write. 70 * @param $mode int (optional) The mode parameter consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means that you grant execute rights, number 2 means that you make the file writeable, number 4 means that you make the file readable. Add up these numbers to specify needed rights. You can also read more about modes on Unix systems with 'man 1 chmod' and 'man 2 chmod'. 71 * @param $type string (optional) The type parameter specifies an additional type of access you require to the file. It may be any of the following: + 72 * @return bool False upon failure. 73 */ 37 74 function put_contents($file, $contents, $mode = false, $type = '') { 38 75 if ( ! ($fp = @fopen($file, 'w' . $type)) ) 39 76 return false; 40 77 @fwrite($fp, $contents); 41 78 @fclose($fp); 42 $this->chmod($file, $mode);79 $this->chmod($file, $mode); 43 80 return true; 44 81 } 82 /** 83 * Gets the current working directory 84 * 85 * @return string|bool the current working directory on success, or false on failure. 86 */ 45 87 function cwd() { 46 88 return @getcwd(); 47 89 } 90 /** 91 * Change directory 92 * 93 * @param $dir string The new current directory. 94 * @return bool Returns true on success or false on failure. 95 */ 48 96 function chdir($dir) { 49 97 return @chdir($dir); 50 98 } 99 /** 100 * Changes file group 101 * 102 * @param $file string Path to the file. 103 * @param $group mixed A group name or number. 104 * @param $recursive bool (optional) If set True changes file group recursivly. Defaults to False. 105 * @return bool Returns true on success or false on failure. 106 */ 51 107 function chgrp($file, $group, $recursive = false) { 52 108 if ( ! $this->exists($file) ) 53 109 return false; … … 63 119 64 120 return true; 65 121 } 122 /** 123 * Changes file mode 124 * 125 * @param $file string Path to the file. 126 * @param $mode int (optional) The mode parameter consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means that you grant execute rights, number 2 means that you make the file writeable, number 4 means that you make the file readable. Add up these numbers to specify needed rights. You can also read more about modes on Unix systems with 'man 1 chmod' and 'man 2 chmod'. 127 * @param $recursive bool (optional) If set True changes file group recursivly. Defaults to False. 128 * @return bool Returns true on success or false on failure. 129 */ 66 130 function chmod($file, $mode = false, $recursive = false) { 67 131 if ( ! $mode ) 68 132 $mode = $this->permission; 69 133 if ( ! $this->exists($file) ) 70 134 return false; 71 135 if ( ! $recursive ) 72 return @chmod($file, $mode);136 return @chmod($file, $mode); 73 137 if ( ! $this->is_dir($file) ) 74 138 return @chmod($file, $mode); 75 139 //Is a directory, and we want recursive … … 80 144 81 145 return true; 82 146 } 147 /** 148 * Changes file owner 149 * 150 * @param $file string Path to the file. 151 * @param $owner mixed A user name or number. 152 * @param $recursive bool (optional) If set True changes file owner recursivly. Defaults to False. 153 * @return bool Returns true on success or false on failure. 154 */ 83 155 function chown($file, $owner, $recursive = false) { 84 156 if ( ! $this->exists($file) ) 85 157 return false; … … 94 166 } 95 167 return true; 96 168 } 169 /** 170 * Gets file owner 171 * 172 * @param $file string Path to the file. 173 * @return string Username of the user. This is a short, usually less than 16 character "handle" of the user, not the real, full name. 174 */ 97 175 function owner($file) { 98 176 $owneruid = @fileowner($file); 99 177 if ( ! $owneruid ) … … 103 181 $ownerarray = posix_getpwuid($owneruid); 104 182 return $ownerarray['name']; 105 183 } 184 /** 185 * Gets file permissions 186 * 187 * FIXME does not handle errors in fileperms() 188 * 189 * @param $file string Path to the file. 190 * @return string Mode of the file (3 chars). 191 */ 106 192 function getchmod($file) { 107 193 return substr(decoct(@fileperms($file)),3); 108 194 } … … 202 288 203 289 if ( ! @mkdir($path, $chmod) ) 204 290 return false; 291 chmod($path, $chmod); // chmod $path because mkdir applies umask to $chmod 205 292 if ( $chown ) 206 293 $this->chown($path, $chown); 207 294 if ( $chgrp )