<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[11831] trunk/wp-admin/includes: WP_Filesystem fixes and phpdoc,
props hakre dd32, see #10304</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11831">11831</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2009-08-16 08:34:53 +0000 (Sun, 16 Aug 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>WP_Filesystem fixes and phpdoc, props hakre dd32, see <a href="http://trac.wordpress.org/ticket/10304">#10304</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswpfilesystembasephp">trunk/wp-admin/includes/class-wp-filesystem-base.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemdirectphp">trunk/wp-admin/includes/class-wp-filesystem-direct.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemftpextphp">trunk/wp-admin/includes/class-wp-filesystem-ftpext.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemftpsocketsphp">trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemssh2php">trunk/wp-admin/includes/class-wp-filesystem-ssh2.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswpfilesystembasephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-base.php (11830 => 11831)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-base.php        2009-08-16 07:43:37 UTC (rev 11830)
+++ trunk/wp-admin/includes/class-wp-filesystem-base.php        2009-08-16 08:34:53 UTC (rev 11831)
</span><span class="lines">@@ -210,7 +210,7 @@
</span><span class="cx">                         return trailingslashit($base . $last_path);
</span><span class="cx">                 }
</span><span class="cx">                 if ( $loop )
</span><del>-                        return false;//Prevent tihs function looping again.
</del><ins>+                        return false; //Prevent tihs function looping again.
</ins><span class="cx">                 //As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
</span><span class="cx">                 return $this->search_for_folder($folder, '/', true);
</span><span class="cx">
</span><span class="lines">@@ -242,7 +242,7 @@
</span><span class="cx">                         $info = 'd';
</span><span class="cx">                 elseif (($perms & 0x2000) == 0x2000) // Character special
</span><span class="cx">                         $info = 'c';
</span><del>-                elseif (($perms & 0x1000) == 0x1000)// FIFO pipe
</del><ins>+                elseif (($perms & 0x1000) == 0x1000) // FIFO pipe
</ins><span class="cx">                         $info = 'p';
</span><span class="cx">                 else // Unknown
</span><span class="cx">                         $info = 'u';
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemdirectphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-direct.php (11830 => 11831)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-direct.php        2009-08-16 07:43:37 UTC (rev 11830)
+++ trunk/wp-admin/includes/class-wp-filesystem-direct.php        2009-08-16 08:34:53 UTC (rev 11831)
</span><span class="lines">@@ -15,38 +15,84 @@
</span><span class="cx"> * @uses WP_Filesystem_Base Extends class
</span><span class="cx"> */
</span><span class="cx"> class WP_Filesystem_Direct extends WP_Filesystem_Base {
</span><del>-        var $permission = null;
</del><span class="cx">         var $errors = null;
</span><ins>+        /**
+         * constructor
+         *
+         * @param $arg mixed ingored argument
+         */
</ins><span class="cx">         function WP_Filesystem_Direct($arg) {
</span><span class="cx">                 $this->method = 'direct';
</span><span class="cx">                 $this->errors = new WP_Error();
</span><span class="cx">         }
</span><ins>+        /**
+         * connect filesystem.
+         *
+         * @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct).
+         */
</ins><span class="cx">         function connect() {
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><del>-        function setDefaultPermissions($perm) {
-                $this->permission = $perm;
-        }
</del><ins>+        /**
+         * Reads entire file into a string
+         *
+         * @param $file string Name of the file to read.
+         * @return string|bool The function returns the read data or false on failure.
+         */
</ins><span class="cx">         function get_contents($file) {
</span><span class="cx">                 return @file_get_contents($file);
</span><span class="cx">         }
</span><ins>+        /**
+         * Reads entire file into an array
+         *
+         * @param $file string Path to the file.
+         * @return array|bool the file contents in an array or false on failure.
+         */
</ins><span class="cx">         function get_contents_array($file) {
</span><span class="cx">                 return @file($file);
</span><span class="cx">         }
</span><ins>+        /**
+         * Write a string to a file
+         *
+         * @param $file string Path to the file where to write the data.
+         * @param $contents string The data to write.
+         * @param $mode int (optional) The file permissions as octal number, usually 0644.
+         * @param $type string (optional) Specifies additional type of access you require to the file.
+         * @return bool False upon failure.
+         */
</ins><span class="cx">         function put_contents($file, $contents, $mode = false, $type = '') {
</span><span class="cx">                 if ( ! ($fp = @fopen($file, 'w' . $type)) )
</span><span class="cx">                         return false;
</span><span class="cx">                 @fwrite($fp, $contents);
</span><span class="cx">                 @fclose($fp);
</span><del>-                $this->chmod($file,$mode);
</del><ins>+                $this->chmod($file, $mode);
</ins><span class="cx">                 return true;
</span><span class="cx">         }
</span><ins>+        /**
+         * Gets the current working directory
+         *
+         * @return string|bool the current working directory on success, or false on failure.
+         */
</ins><span class="cx">         function cwd() {
</span><span class="cx">                 return @getcwd();
</span><span class="cx">         }
</span><ins>+        /**
+         * Change directory
+         *
+         * @param $dir string The new current directory.
+         * @return bool Returns true on success or false on failure.
+         */
</ins><span class="cx">         function chdir($dir) {
</span><span class="cx">                 return @chdir($dir);
</span><span class="cx">         }
</span><ins>+        /**
+         * Changes file group
+         *
+         * @param $file string Path to the file.
+         * @param $group mixed A group name or number.
+         * @param $recursive bool (optional) If set True changes file group recursivly. Defaults to False.
+         * @return bool Returns true on success or false on failure.
+         */
</ins><span class="cx">         function chgrp($file, $group, $recursive = false) {
</span><span class="cx">                 if ( ! $this->exists($file) )
</span><span class="cx">                         return false;
</span><span class="lines">@@ -62,14 +108,20 @@
</span><span class="cx">
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><ins>+        /**
+         * Changes filesystem permissions
+         *
+         * @param $file string Path to the file.
+         * @param $mode int (optional) The permissions as octal number, usually 0644 for files, 0755 for dirs.
+         * @param $recursive bool (optional) If set True changes file group recursivly. Defaults to False.
+         * @return bool Returns true on success or false on failure.
+         */
</ins><span class="cx">         function chmod($file, $mode = false, $recursive = false) {
</span><span class="cx">                 if ( ! $this->exists($file) )
</span><span class="cx">                         return false;
</span><span class="cx">
</span><span class="cx">                 if ( ! $mode ) {
</span><del>-                        if ( $this->permission )
-                                $mode = $this->permission;
-                        elseif ( $this->is_file($file) )
</del><ins>+                        if ( $this->is_file($file) )
</ins><span class="cx">                                 $mode = FS_CHMOD_FILE;
</span><span class="cx">                         elseif ( $this->is_dir($file) )
</span><span class="cx">                                 $mode = FS_CHMOD_DIR;
</span><span class="lines">@@ -89,6 +141,14 @@
</span><span class="cx">
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><ins>+        /**
+         * Changes file owner
+         *
+         * @param $file string Path to the file.
+         * @param $owner mixed A user name or number.
+         * @param $recursive bool (optional) If set True changes file owner recursivly. Defaults to False.
+         * @return bool Returns true on success or false on failure.
+         */
</ins><span class="cx">         function chown($file, $owner, $recursive = false) {
</span><span class="cx">                 if ( ! $this->exists($file) )
</span><span class="cx">                         return false;
</span><span class="lines">@@ -98,11 +158,17 @@
</span><span class="cx">                         return @chown($file, $owner);
</span><span class="cx">                 //Is a directory, and we want recursive
</span><span class="cx">                 $filelist = $this->dirlist($file);
</span><del>-                foreach ($filelist as $filename){
</del><ins>+                foreach ($filelist as $filename) {
</ins><span class="cx">                         $this->chown($file . '/' . $filename, $owner, $recursive);
</span><span class="cx">                 }
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><ins>+        /**
+         * Gets file owner
+         *
+         * @param $file string Path to the file.
+         * @return string Username of the user.
+         */
</ins><span class="cx">         function owner($file) {
</span><span class="cx">                 $owneruid = @fileowner($file);
</span><span class="cx">                 if ( ! $owneruid )
</span><span class="lines">@@ -112,6 +178,14 @@
</span><span class="cx">                 $ownerarray = posix_getpwuid($owneruid);
</span><span class="cx">                 return $ownerarray['name'];
</span><span class="cx">         }
</span><ins>+        /**
+         * Gets file permissions
+         *
+         * FIXME does not handle errors in fileperms()
+         *
+         * @param $file string Path to the file.
+         * @return string Mode of the file (last 4 digits).
+         */
</ins><span class="cx">         function getchmod($file) {
</span><span class="cx">                 return substr(decoct(@fileperms($file)),3);
</span><span class="cx">         }
</span><span class="lines">@@ -133,7 +207,7 @@
</span><span class="cx">
</span><span class="cx">         function move($source, $destination, $overwrite = false) {
</span><span class="cx">                 //Possible to use rename()?
</span><del>-                if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ){
</del><ins>+                if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ) {
</ins><span class="cx">                         $this->delete($source);
</span><span class="cx">                         return true;
</span><span class="cx">                 } else {
</span><span class="lines">@@ -197,7 +271,7 @@
</span><span class="cx">                 return @filesize($file);
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function touch($file, $time = 0, $atime = 0){
</del><ins>+        function touch($file, $time = 0, $atime = 0) {
</ins><span class="cx">                 if ($time == 0)
</span><span class="cx">                         $time = time();
</span><span class="cx">                 if ($atime == 0)
</span><span class="lines">@@ -205,7 +279,10 @@
</span><span class="cx">                 return @touch($file, $time, $atime);
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function mkdir($path, $chmod = false, $chown = false, $chgrp = false){
</del><ins>+        function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
+                if ( ! $chmod )
+                        $chmod = FS_CHMOD_DIR;
+
</ins><span class="cx">                 if ( ! @mkdir($path) )
</span><span class="cx">                         return false;
</span><span class="cx">                 $this->chmod($path, $chmod);
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemftpextphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ftpext.php (11830 => 11831)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ftpext.php        2009-08-16 07:43:37 UTC (rev 11830)
+++ trunk/wp-admin/includes/class-wp-filesystem-ftpext.php        2009-08-16 08:34:53 UTC (rev 11831)
</span><span class="lines">@@ -19,8 +19,6 @@
</span><span class="cx">         var $errors = null;
</span><span class="cx">         var $options = array();
</span><span class="cx">
</span><del>-        var $permission = null;
-
</del><span class="cx">         function WP_Filesystem_FTPext($opt='') {
</span><span class="cx">                 $this->method = 'ftpext';
</span><span class="cx">                 $this->errors = new WP_Error();
</span><span class="lines">@@ -90,19 +88,15 @@
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function setDefaultPermissions($perm) {
-                $this->permission = $perm;
-        }
-
-        function get_contents($file, $type = '', $resumepos = 0 ){
-                if( empty($type) )
</del><ins>+        function get_contents($file, $type = '', $resumepos = 0 ) {
+                if ( empty($type) )
</ins><span class="cx">                         $type = FTP_BINARY;
</span><span class="cx">
</span><span class="cx">                 $temp = tmpfile();
</span><span class="cx">                 if ( ! $temp )
</span><span class="cx">                         return false;
</span><span class="cx">
</span><del>-                if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
</del><ins>+                if ( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><span class="cx">                 fseek($temp, 0); //Skip back to the start of the file being written to
</span><span class="lines">@@ -118,7 +112,7 @@
</span><span class="cx">                 return explode("\n", $this->get_contents($file));
</span><span class="cx">         }
</span><span class="cx">         function put_contents($file, $contents, $type = '' ) {
</span><del>-                if( empty($type) )
</del><ins>+                if ( empty($type) )
</ins><span class="cx">                         $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
</span><span class="cx">
</span><span class="cx">                 $temp = tmpfile();
</span><span class="lines">@@ -135,7 +129,7 @@
</span><span class="cx">         }
</span><span class="cx">         function cwd() {
</span><span class="cx">                 $cwd = @ftp_pwd($this->link);
</span><del>-                if( $cwd )
</del><ins>+                if ( $cwd )
</ins><span class="cx">                         $cwd = trailingslashit($cwd);
</span><span class="cx">                 return $cwd;
</span><span class="cx">         }
</span><span class="lines">@@ -146,12 +140,18 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">         function chmod($file, $mode = false, $recursive = false) {
</span><del>-                if( ! $mode )
-                        $mode = $this->permission;
-                if( ! $mode )
-                        return false;
</del><span class="cx">                 if ( ! $this->exists($file) && ! $this->is_dir($file) )
</span><span class="cx">                         return false;
</span><ins>+
+                if ( ! $mode ) {
+                        if ( $this->is_file($file) )
+                                $mode = FS_CHMOD_FILE;
+                        elseif ( $this->is_dir($file) )
+                                $mode = FS_CHMOD_DIR;
+                        else
+                                return false;        
+                }
+
</ins><span class="cx">                 if ( ! $recursive || ! $this->is_dir($file) ) {
</span><span class="cx">                         if ( ! function_exists('ftp_chmod') )
</span><span class="cx">                                 return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
</span><span class="lines">@@ -159,7 +159,7 @@
</span><span class="cx">                 }
</span><span class="cx">                 //Is a directory, and we want recursive
</span><span class="cx">                 $filelist = $this->dirlist($file);
</span><del>-                foreach($filelist as $filename){
</del><ins>+                foreach ( $filelist as $filename ) {
</ins><span class="cx">                         $this->chmod($file . '/' . $filename, $mode, $recursive);
</span><span class="cx">                 }
</span><span class="cx">                 return true;
</span><span class="lines">@@ -180,10 +180,10 @@
</span><span class="cx">                 return $dir[$file]['group'];
</span><span class="cx">         }
</span><span class="cx">         function copy($source, $destination, $overwrite = false ) {
</span><del>-                if( ! $overwrite && $this->exists($destination) )
</del><ins>+                if ( ! $overwrite && $this->exists($destination) )
</ins><span class="cx">                         return false;
</span><span class="cx">                 $content = $this->get_contents($source);
</span><del>-                if( false === $content)
</del><ins>+                if ( false === $content)
</ins><span class="cx">                         return false;
</span><span class="cx">                 return $this->put_contents($destination, $content);
</span><span class="cx">         }
</span><span class="lines">@@ -216,7 +216,7 @@
</span><span class="cx">         function is_dir($path) {
</span><span class="cx">                 $cwd = $this->cwd();
</span><span class="cx">                 $result = @ftp_chdir($this->link, trailingslashit($path) );
</span><del>-                if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
</del><ins>+                if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
</ins><span class="cx">                         @ftp_chdir($this->link, $cwd);
</span><span class="cx">                         return true;
</span><span class="cx">                 }
</span><span class="lines">@@ -243,13 +243,14 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">         function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
</span><del>-                if( !ftp_mkdir($this->link, $path) )
</del><ins>+                if ( !ftp_mkdir($this->link, $path) )
</ins><span class="cx">                         return false;
</span><del>-                if( $chmod )
-                        $this->chmod($path, $chmod);
-                if( $chown )
</del><ins>+                if ( ! $chmod )
+                        $chmod = FS_CHMOD_DIR;
+                $this->chmod($path, $chmod);
+                if ( $chown )
</ins><span class="cx">                         $this->chown($path, $chown);
</span><del>-                if( $chgrp )
</del><ins>+                if ( $chgrp )
</ins><span class="cx">                         $this->chgrp($path, $chgrp);
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="lines">@@ -262,9 +263,9 @@
</span><span class="cx">                 if ( is_null($is_windows) )
</span><span class="cx">                         $is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false;
</span><span class="cx">
</span><del>-                if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer)) {
</del><ins>+                if ( $is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer) ) {
</ins><span class="cx">                         $b = array();
</span><del>-                        if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
</del><ins>+                        if ( $lucifer[3] < 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix
</ins><span class="cx">                         $b['isdir'] = ($lucifer[7]=="<DIR>");
</span><span class="cx">                         if ( $b['isdir'] )
</span><span class="cx">                                 $b['type'] = 'd';
</span><span class="lines">@@ -323,7 +324,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function dirlist($path = '.', $incdot = false, $recursive = false) {
</span><del>-                if( $this->is_file($path) ) {
</del><ins>+                if ( $this->is_file($path) ) {
</ins><span class="cx">                         $limitFile = basename($path);
</span><span class="cx">                         $path = dirname($path) . '/';
</span><span class="cx">                 } else {
</span><span class="lines">@@ -358,9 +359,9 @@
</span><span class="cx">                         if ( 'd' == $struc['type'] ) {
</span><span class="cx">                                 $struc['files'] = array();
</span><span class="cx">
</span><del>-                                if ( $incdot ){
</del><ins>+                                if ( $incdot ) {
</ins><span class="cx">                                         //We're including the doted starts
</span><del>-                                        if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
</del><ins>+                                        if ( '.' != $struc['name'] && '..' != $struc['name'] ) { //Ok, It isnt a special folder
</ins><span class="cx">                                                 if ($recursive)
</span><span class="cx">                                                         $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
</span><span class="cx">                                         }
</span><span class="lines">@@ -375,8 +376,8 @@
</span><span class="cx">                 return $ret;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function __destruct(){
-                if( $this->link )
</del><ins>+        function __destruct() {
+                if ( $this->link )
</ins><span class="cx">                         ftp_close($this->link);
</span><span class="cx">         }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemftpsocketsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php (11830 => 11831)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php        2009-08-16 07:43:37 UTC (rev 11830)
+++ trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php        2009-08-16 08:34:53 UTC (rev 11831)
</span><span class="lines">@@ -19,14 +19,12 @@
</span><span class="cx">         var $errors = null;
</span><span class="cx">         var $options = array();
</span><span class="cx">
</span><del>-        var $permission = null;
-
</del><span class="cx">         function WP_Filesystem_ftpsockets($opt = '') {
</span><span class="cx">                 $this->method = 'ftpsockets';
</span><span class="cx">                 $this->errors = new WP_Error();
</span><span class="cx">
</span><span class="cx">                 //Check if possible to use ftp functions.
</span><del>-                if( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )
</del><ins>+                if ( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' )
</ins><span class="cx">                                 return false;
</span><span class="cx">                 $this->ftp = new ftp();
</span><span class="cx">
</span><span class="lines">@@ -83,15 +81,11 @@
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function setDefaultPermissions($perm) {
-                $this->permission = $perm;
-        }
-
</del><span class="cx">         function get_contents($file, $type = '', $resumepos = 0) {
</span><del>-                if( ! $this->exists($file) )
</del><ins>+                if ( ! $this->exists($file) )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><del>-                if( empty($type) )
</del><ins>+                if ( empty($type) )
</ins><span class="cx">                         $type = FTP_AUTOASCII;
</span><span class="cx">                 $this->ftp->SetType($type);
</span><span class="cx">
</span><span class="lines">@@ -122,7 +116,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function put_contents($file, $contents, $type = '' ) {
</span><del>-                if( empty($type) )
</del><ins>+                if ( empty($type) )
</ins><span class="cx">                         $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
</span><span class="cx">
</span><span class="cx">                 $this->ftp->SetType($type);
</span><span class="lines">@@ -145,7 +139,7 @@
</span><span class="cx">
</span><span class="cx">         function cwd() {
</span><span class="cx">                 $cwd = $this->ftp->pwd();
</span><del>-                if( $cwd )
</del><ins>+                if ( $cwd )
</ins><span class="cx">                         $cwd = trailingslashit($cwd);
</span><span class="cx">                 return $cwd;
</span><span class="cx">         }
</span><span class="lines">@@ -159,15 +153,19 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function chmod($file, $mode = false, $recursive = false ) {
</span><del>-                if( ! $mode )
-                        $mode = $this->permission;
-                if( ! $mode )
-                        return false;
-                //if( ! $this->exists($file) )
-                //        return false;
-                if( ! $recursive || ! $this->is_dir($file) ) {
-                        return $this->ftp->chmod($file,$mode);
</del><ins>+
+                if ( ! $mode ) {
+                        if ( $this->is_file($file) )
+                                $mode = FS_CHMOD_FILE;
+                        elseif ( $this->is_dir($file) )
+                                $mode = FS_CHMOD_DIR;
+                        else
+                                return false;        
</ins><span class="cx">                 }
</span><ins>+
+                if ( ! $recursive || ! $this->is_dir($file) ) {
+                        return $this->ftp->chmod($file, $mode);
+                }
</ins><span class="cx">                 //Is a directory, and we want recursive
</span><span class="cx">                 $filelist = $this->dirlist($file);
</span><span class="cx">                 foreach($filelist as $filename){
</span><span class="lines">@@ -196,7 +194,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function copy($source, $destination, $overwrite = false ) {
</span><del>-                if( ! $overwrite && $this->exists($destination) )
</del><ins>+                if ( ! $overwrite && $this->exists($destination) )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><span class="cx">                 $content = $this->get_contents($source);
</span><span class="lines">@@ -265,26 +263,27 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) {
</span><del>-                if( ! $this->ftp->mkdir($path) )
</del><ins>+                if ( ! $this->ftp->mkdir($path) )
</ins><span class="cx">                         return false;
</span><del>-                if( $chmod )
-                        $this->chmod($path, $chmod);
-                if( $chown )
</del><ins>+                if ( ! $chmod )
+                        $chmod = FS_CHMOD_DIR;
+                $this->chmod($path, $chmod);
+                if ( $chown )
</ins><span class="cx">                         $this->chown($path, $chown);
</span><del>-                if( $chgrp )
</del><ins>+                if ( $chgrp )
</ins><span class="cx">                         $this->chgrp($path, $chgrp);
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function rmdir($path, $recursive = false ) {
</span><del>-                if( ! $recursive )
</del><ins>+                if ( ! $recursive )
</ins><span class="cx">                         return $this->ftp->rmdir($path);
</span><span class="cx">
</span><span class="cx">                 return $this->ftp->mdel($path);
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function dirlist($path = '.', $incdot = false, $recursive = false ) {
</span><del>-                if( $this->is_file($path) ) {
</del><ins>+                if ( $this->is_file($path) ) {
</ins><span class="cx">                         $limitFile = basename($path);
</span><span class="cx">                         $path = dirname($path) . '/';
</span><span class="cx">                 } else {
</span><span class="lines">@@ -292,9 +291,9 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 $list = $this->ftp->dirlist($path);
</span><del>-                if( ! $list )
</del><ins>+                if ( ! $list )
</ins><span class="cx">                         return false;
</span><del>-                if( empty($list) )
</del><ins>+                if ( empty($list) )
</ins><span class="cx">                         return array();
</span><span class="cx">
</span><span class="cx">                 $ret = array();
</span><span class="lines">@@ -305,7 +304,7 @@
</span><span class="cx">
</span><span class="cx">                                 if ( $incdot ){
</span><span class="cx">                                         //We're including the doted starts
</span><del>-                                        if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
</del><ins>+                                        if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
</ins><span class="cx">                                                 if ($recursive)
</span><span class="cx">                                                         $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
</span><span class="cx">                                         }
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemssh2php"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ssh2.php (11830 => 11831)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ssh2.php        2009-08-16 07:43:37 UTC (rev 11830)
+++ trunk/wp-admin/includes/class-wp-filesystem-ssh2.php        2009-08-16 08:34:53 UTC (rev 11831)
</span><span class="lines">@@ -48,8 +48,6 @@
</span><span class="cx">         var $errors = array();
</span><span class="cx">         var $options = array();
</span><span class="cx">
</span><del>-        var $permission = 0644;
-
</del><span class="cx">         function WP_Filesystem_SSH2($opt='') {
</span><span class="cx">                 $this->method = 'ssh2';
</span><span class="cx">                 $this->errors = new WP_Error();
</span><span class="lines">@@ -152,12 +150,6 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function setDefaultPermissions($perm) {
-                $this->debug("setDefaultPermissions();");
-                if ( $perm )
-                        $this->permission = $perm;
-        }
-
</del><span class="cx">         function get_contents($file, $type = '', $resumepos = 0 ) {
</span><span class="cx">                 $file = ltrim($file, '/');
</span><span class="cx">                 return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file);
</span><span class="lines">@@ -193,12 +185,18 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function chmod($file, $mode = false, $recursive = false) {
</span><del>-                if( ! $mode )
-                        $mode = $this->permission;
-                if( ! $mode )
-                        return false;
</del><span class="cx">                 if ( ! $this->exists($file) )
</span><span class="cx">                         return false;
</span><ins>+
+                if ( ! $mode ) {
+                        if ( $this->is_file($file) )
+                                $mode = FS_CHMOD_FILE;
+                        elseif ( $this->is_dir($file) )
+                                $mode = FS_CHMOD_DIR;
+                        else
+                                return false;        
+                }
+
</ins><span class="cx">                 if ( ! $recursive || ! $this->is_dir($file) )
</span><span class="cx">                         return $this->run_command(sprintf('chmod %o %s', $mode, escapeshellarg($file)), true);
</span><span class="cx">                 return $this->run_command(sprintf('chmod -R %o %s', $mode, escapeshellarg($file)), true);
</span><span class="lines">@@ -307,9 +305,10 @@
</span><span class="cx">                 //Not implmented.
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {
</del><ins>+        function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
</ins><span class="cx">                 $path = untrailingslashit($path);
</span><del>-                $chmod = !empty($chmod) ? $chmod : $this->permission;
</del><ins>+                if ( ! $chmod )
+                        $chmod = FS_CHMOD_DIR;
</ins><span class="cx">                 if ( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) )
</span><span class="cx">                         return false;
</span><span class="cx">                 if ( $chown )
</span></span></pre>
</div>
</div>
</body>
</html>