<!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>[17580] trunk/wp-admin/includes/update-core.php:
  Back-compat for core upgrades with pre-3.2.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17580">17580</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2011-04-01 09:50:01 +0000 (Fri, 01 Apr 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Back-compat for core upgrades with pre-3.2. Utilises a temporary _copy_dir() function which can be removed in 3.3-dev to bring immediate wp-content relief to the 3.1-3.2 upgrades. See <a href="http://trac.wordpress.org/ticket/14484">#14484</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesupdatecorephp">trunk/wp-admin/includes/update-core.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesupdatecorephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/update-core.php (17579 => 17580)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/update-core.php        2011-04-01 09:17:27 UTC (rev 17579)
+++ trunk/wp-admin/includes/update-core.php        2011-04-01 09:50:01 UTC (rev 17580)
</span><span class="lines">@@ -363,7 +363,7 @@
</span><span class="cx">         $wp_filesystem-&gt;put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
</span><span class="cx"> 
</span><span class="cx">         // Copy new versions of WP files into place.
</span><del>-        $result = copy_dir($from . $distro, $to, array('wp-content') );
</del><ins>+        $result = _copy_dir($from . $distro, $to, array('wp-content') );
</ins><span class="cx"> 
</span><span class="cx">         // Custom Content Directory needs updating now.
</span><span class="cx">         // Copy Languages
</span><span class="lines">@@ -394,19 +394,22 @@
</span><span class="cx">                         if ( version_compare($introduced_version, $old_version, '&gt;') ) {
</span><span class="cx">                                 $directory = ('/' == $file[ strlen($file)-1 ]);
</span><span class="cx">                                 list($type, $filename) = explode('/', $file, 2);
</span><ins>+
</ins><span class="cx">                                 if ( 'plugins' == $type )
</span><span class="cx">                                         $dest = $wp_filesystem-&gt;wp_plugins_dir();
</span><span class="cx">                                 elseif ( 'themes' == $type )
</span><del>-                                        $dest = $wp_filesystem-&gt;wp_themes_dir();
</del><ins>+                                        $dest = trailingslashit($wp_filesystem-&gt;wp_themes_dir()); // Back-compat, ::wp_themes_dir() did not return trailingslash'd pre-3.2
+                                else
+                                        continue;
</ins><span class="cx"> 
</span><span class="cx">                                 if ( ! $directory ) {
</span><del>-                                        if ( $wp_filesystem-&gt;exists($dest . '/' . $filename) )
</del><ins>+                                        if ( $wp_filesystem-&gt;exists($dest . $filename) )
</ins><span class="cx">                                                 continue;
</span><span class="cx"> 
</span><del>-                                        if ( ! $wp_filesystem-&gt;copy($from . $distro . 'wp-content/' . $file, $dest . '/' . $filename, FS_CHMOD_FILE) )
-                                                $result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . '/' . $filename);
</del><ins>+                                        if ( ! $wp_filesystem-&gt;copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE) )
+                                                $result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . $filename);
</ins><span class="cx">                                 } else {
</span><del>-                                        if ( $wp_filesystem-&gt;is_dir($dest . '/' . $filename) )
</del><ins>+                                        if ( $wp_filesystem-&gt;is_dir($dest . $filename) )
</ins><span class="cx">                                                 continue;
</span><span class="cx"> 
</span><span class="cx">                                         $wp_filesystem-&gt;mkdir($dest . $filename, FS_CHMOD_DIR);
</span><span class="lines">@@ -451,4 +454,59 @@
</span><span class="cx">         $wp_filesystem-&gt;delete($maintenance_file);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**#@+
+ * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
+ * Assumes that WP_Filesystem() has already been called and setup.
+ *
+ * This is a temporary function for the 3.1 -&gt; 3.2 upgrade only and will be removed in 3.3
+ *
+ * @since 3.2
+ * @see copy_dir()
+ *
+ * @param string $from source directory
+ * @param string $to destination directory
+ * @param array $skip_list a list of files/folders to skip copying
+ * @return mixed WP_Error on failure, True on success.
+ */
+function _copy_dir($from, $to, $skip_list = array() ) {
+        global $wp_filesystem;
+
+        $dirlist = $wp_filesystem-&gt;dirlist($from);
+
+        $from = trailingslashit($from);
+        $to = trailingslashit($to);
+
+        $skip_regex = '';
+        foreach ( (array)$skip_list as $key =&gt; $skip_file )
+                $skip_regex .= preg_quote($skip_file, '!') . '|';
+
+        if ( !empty($skip_regex) )
+                $skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
+
+        foreach ( (array) $dirlist as $filename =&gt; $fileinfo ) {
+                if ( !empty($skip_regex) )
+                        if ( preg_match($skip_regex, $from . $filename) )
+                                continue;
+
+                if ( 'f' == $fileinfo['type'] ) {
+                        if ( ! $wp_filesystem-&gt;copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
+                                // If copy failed, chmod file to 0644 and try again.
+                                $wp_filesystem-&gt;chmod($to . $filename, 0644);
+                                if ( ! $wp_filesystem-&gt;copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
+                                        return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
+                        }
+                } elseif ( 'd' == $fileinfo['type'] ) {
+                        if ( !$wp_filesystem-&gt;is_dir($to . $filename) ) {
+                                if ( !$wp_filesystem-&gt;mkdir($to . $filename, FS_CHMOD_DIR) )
+                                        return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
+                        }
+                        $result = _copy_dir($from . $filename, $to . $filename, $skip_list);
+                        if ( is_wp_error($result) )
+                                return $result;
+                }
+        }
+        return true;
+}
+/**#@-*/
+
</ins><span class="cx"> ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>