<!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 { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { 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>[17525] trunk/wp-admin/includes: Optimisations to WP_Filesystem;
  Pass known information to called functions.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17525">17525</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2011-03-22 00:04:15 +0000 (Tue, 22 Mar 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Optimisations to WP_Filesystem; Pass known information to called functions. Props aldenta (John Ford) for investigation and patch. See <a href="http://trac.wordpress.org/ticket/10913">#10913</a></pre>

<h3>Modified Paths</h3>
<ul>
<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>
<li><a href="#trunkwpadminincludesfilephp">trunk/wp-admin/includes/file.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswpfilesystemdirectphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-direct.php (17524 => 17525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-direct.php        2011-03-21 23:44:30 UTC (rev 17524)
+++ trunk/wp-admin/includes/class-wp-filesystem-direct.php        2011-03-22 00:04:15 UTC (rev 17525)
</span><span class="lines">@@ -193,11 +193,14 @@
</span><span class="cx">                 return $grouparray['name'];
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function copy($source, $destination, $overwrite = false) {
</del><ins>+        function copy($source, $destination, $overwrite = false, $mode = false) {
</ins><span class="cx">                 if ( ! $overwrite &amp;&amp; $this-&gt;exists($destination) )
</span><span class="cx">                         return false;
</span><span class="cx"> 
</span><del>-                return copy($source, $destination);
</del><ins>+                $rtval = copy($source, $destination);
+                if ( $mode )
+                        $this-&gt;chmod($destination, $mode);
+                return $rtval;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function move($source, $destination, $overwrite = false) {
</span><span class="lines">@@ -216,12 +219,12 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function delete($file, $recursive = false) {
</del><ins>+        function delete($file, $recursive = false, $type = false) {
</ins><span class="cx">                 if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
</span><span class="cx">                         return false;
</span><span class="cx">                 $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
</span><span class="cx"> 
</span><del>-                if ( $this-&gt;is_file($file) )
</del><ins>+                if ( 'f' == $type || $this-&gt;is_file($file) )
</ins><span class="cx">                         return @unlink($file);
</span><span class="cx">                 if ( ! $recursive &amp;&amp; $this-&gt;is_dir($file) )
</span><span class="cx">                         return @rmdir($file);
</span><span class="lines">@@ -233,7 +236,7 @@
</span><span class="cx">                 $retval = true;
</span><span class="cx">                 if ( is_array($filelist) ) //false if no files, So check first.
</span><span class="cx">                         foreach ($filelist as $filename =&gt; $fileinfo)
</span><del>-                                if ( ! $this-&gt;delete($file . $filename, $recursive) )
</del><ins>+                                if ( ! $this-&gt;delete($file . $filename, $recursive, $fileinfo['type']) )
</ins><span class="cx">                                         $retval = false;
</span><span class="cx"> 
</span><span class="cx">                 if ( file_exists($file) &amp;&amp; ! @rmdir($file) )
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemftpextphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ftpext.php (17524 => 17525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ftpext.php        2011-03-21 23:44:30 UTC (rev 17524)
+++ trunk/wp-admin/includes/class-wp-filesystem-ftpext.php        2011-03-22 00:04:15 UTC (rev 17525)
</span><span class="lines">@@ -183,22 +183,22 @@
</span><span class="cx">                 $dir = $this-&gt;dirlist($file);
</span><span class="cx">                 return $dir[$file]['group'];
</span><span class="cx">         }
</span><del>-        function copy($source, $destination, $overwrite = false ) {
</del><ins>+        function copy($source, $destination, $overwrite = false, $mode = false) {
</ins><span class="cx">                 if ( ! $overwrite &amp;&amp; $this-&gt;exists($destination) )
</span><span class="cx">                         return false;
</span><span class="cx">                 $content = $this-&gt;get_contents($source);
</span><span class="cx">                 if ( false === $content)
</span><span class="cx">                         return false;
</span><del>-                return $this-&gt;put_contents($destination, $content);
</del><ins>+                return $this-&gt;put_contents($destination, $content, $mode);
</ins><span class="cx">         }
</span><span class="cx">         function move($source, $destination, $overwrite = false) {
</span><span class="cx">                 return ftp_rename($this-&gt;link, $source, $destination);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function delete($file, $recursive = false ) {
</del><ins>+        function delete($file, $recursive = false, $type = false) {
</ins><span class="cx">                 if ( empty($file) )
</span><span class="cx">                         return false;
</span><del>-                if ( $this-&gt;is_file($file) )
</del><ins>+                if ( 'f' == $type || $this-&gt;is_file($file) )
</ins><span class="cx">                         return @ftp_delete($this-&gt;link, $file);
</span><span class="cx">                 if ( !$recursive )
</span><span class="cx">                         return @ftp_rmdir($this-&gt;link, $file);
</span><span class="lines">@@ -206,7 +206,7 @@
</span><span class="cx">                 $filelist = $this-&gt;dirlist( trailingslashit($file) );
</span><span class="cx">                 if ( !empty($filelist) )
</span><span class="cx">                         foreach ( $filelist as $delete_file )
</span><del>-                                $this-&gt;delete( trailingslashit($file) . $delete_file['name'], $recursive);
</del><ins>+                                $this-&gt;delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] );
</ins><span class="cx">                 return @ftp_rmdir($this-&gt;link, $file);
</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 (17524 => 17525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php        2011-03-21 23:44:30 UTC (rev 17524)
+++ trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php        2011-03-22 00:04:15 UTC (rev 17525)
</span><span class="lines">@@ -193,7 +193,7 @@
</span><span class="cx">                 return $dir[$file]['group'];
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function copy($source, $destination, $overwrite = false ) {
</del><ins>+        function copy($source, $destination, $overwrite = false, $mode = false) {
</ins><span class="cx">                 if ( ! $overwrite &amp;&amp; $this-&gt;exists($destination) )
</span><span class="cx">                         return false;
</span><span class="cx"> 
</span><span class="lines">@@ -201,17 +201,17 @@
</span><span class="cx">                 if ( false === $content )
</span><span class="cx">                         return false;
</span><span class="cx"> 
</span><del>-                return $this-&gt;put_contents($destination, $content);
</del><ins>+                return $this-&gt;put_contents($destination, $content, $mode);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function move($source, $destination, $overwrite = false ) {
</span><span class="cx">                 return $this-&gt;ftp-&gt;rename($source, $destination);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function delete($file, $recursive = false ) {
</del><ins>+        function delete($file, $recursive = false, $type = false) {
</ins><span class="cx">                 if ( empty($file) )
</span><span class="cx">                         return false;
</span><del>-                if ( $this-&gt;is_file($file) )
</del><ins>+                if ( 'f' == $type || $this-&gt;is_file($file) )
</ins><span class="cx">                         return $this-&gt;ftp-&gt;delete($file);
</span><span class="cx">                 if ( !$recursive )
</span><span class="cx">                         return $this-&gt;ftp-&gt;rmdir($file);
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemssh2php"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ssh2.php (17524 => 17525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ssh2.php        2011-03-21 23:44:30 UTC (rev 17524)
+++ trunk/wp-admin/includes/class-wp-filesystem-ssh2.php        2011-03-22 00:04:15 UTC (rev 17525)
</span><span class="lines">@@ -238,28 +238,28 @@
</span><span class="cx">                 return $grouparray['name'];
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function copy($source, $destination, $overwrite = false ) {
</del><ins>+        function copy($source, $destination, $overwrite = false, $mode = false) {
</ins><span class="cx">                 if ( ! $overwrite &amp;&amp; $this-&gt;exists($destination) )
</span><span class="cx">                         return false;
</span><span class="cx">                 $content = $this-&gt;get_contents($source);
</span><span class="cx">                 if ( false === $content)
</span><span class="cx">                         return false;
</span><del>-                return $this-&gt;put_contents($destination, $content);
</del><ins>+                return $this-&gt;put_contents($destination, $content, $mode);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function move($source, $destination, $overwrite = false) {
</span><span class="cx">                 return @ssh2_sftp_rename($this-&gt;link, $source, $destination);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function delete($file, $recursive = false) {
-                if ( $this-&gt;is_file($file) )
</del><ins>+        function delete($file, $recursive = false, $type = false) {
+                if ( 'f' == $type || $this-&gt;is_file($file) )
</ins><span class="cx">                         return ssh2_sftp_unlink($this-&gt;sftp_link, $file);
</span><span class="cx">                 if ( ! $recursive )
</span><span class="cx">                          return ssh2_sftp_rmdir($this-&gt;sftp_link, $file);
</span><span class="cx">                 $filelist = $this-&gt;dirlist($file);
</span><span class="cx">                 if ( is_array($filelist) ) {
</span><span class="cx">                         foreach ( $filelist as $filename =&gt; $fileinfo) {
</span><del>-                                $this-&gt;delete($file . '/' . $filename, $recursive);
</del><ins>+                                $this-&gt;delete($file . '/' . $filename, $recursive, $fileinfo['type']);
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">                 return ssh2_sftp_rmdir($this-&gt;sftp_link, $file);
</span></span></pre></div>
<a id="trunkwpadminincludesfilephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/file.php (17524 => 17525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/file.php        2011-03-21 23:44:30 UTC (rev 17524)
+++ trunk/wp-admin/includes/file.php        2011-03-22 00:04:15 UTC (rev 17525)
</span><span class="lines">@@ -80,9 +80,9 @@
</span><span class="cx">         $home = get_option( 'home' );
</span><span class="cx">         $siteurl = get_option( 'siteurl' );
</span><span class="cx">         if ( $home != '' &amp;&amp; $home != $siteurl ) {
</span><del>-                $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */
-                $pos = strpos($_SERVER[&quot;SCRIPT_FILENAME&quot;], $wp_path_rel_to_home);
-                $home_path = substr($_SERVER[&quot;SCRIPT_FILENAME&quot;], 0, $pos);
</del><ins>+                $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */
+                $pos = strpos($_SERVER[&quot;SCRIPT_FILENAME&quot;], $wp_path_rel_to_home);
+                $home_path = substr($_SERVER[&quot;SCRIPT_FILENAME&quot;], 0, $pos);
</ins><span class="cx">                 $home_path = trailingslashit( $home_path );
</span><span class="cx">         } else {
</span><span class="cx">                 $home_path = ABSPATH;
</span><span class="lines">@@ -773,13 +773,12 @@
</span><span class="cx"> 
</span><span class="cx">         foreach ( (array) $dirlist as $filename =&gt; $fileinfo ) {
</span><span class="cx">                 if ( 'f' == $fileinfo['type'] ) {
</span><del>-                        if ( ! $wp_filesystem-&gt;copy($from . $filename, $to . $filename, true) ) {
</del><ins>+                        if ( ! $wp_filesystem-&gt;copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
</ins><span class="cx">                                 // If copy failed, chmod file to 0644 and try again.
</span><span class="cx">                                 $wp_filesystem-&gt;chmod($to . $filename, 0644);
</span><del>-                                if ( ! $wp_filesystem-&gt;copy($from . $filename, $to . $filename, true) )
</del><ins>+                                if ( ! $wp_filesystem-&gt;copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
</ins><span class="cx">                                         return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
</span><span class="cx">                         }
</span><del>-                        $wp_filesystem-&gt;chmod($to . $filename, FS_CHMOD_FILE);
</del><span class="cx">                 } elseif ( 'd' == $fileinfo['type'] ) {
</span><span class="cx">                         if ( !$wp_filesystem-&gt;is_dir($to . $filename) ) {
</span><span class="cx">                                 if ( !$wp_filesystem-&gt;mkdir($to . $filename, FS_CHMOD_DIR) )
</span></span></pre>
</div>
</div>

</body>
</html>