<!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" />
<title>[25763] trunk/src/wp-admin/includes: Refine error codes throughout the upgrader so we can better detect at what stage updates fail.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/25763">25763</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-10-11 16:05:13 +0000 (Fri, 11 Oct 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Refine error codes throughout the upgrader so we can better detect at what stage updates fail.

see <a href="http://core.trac.wordpress.org/ticket/22704">#22704</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswpupgraderphp">trunk/src/wp-admin/includes/class-wp-upgrader.php</a></li>
<li><a href="#trunksrcwpadminincludesfilephp">trunk/src/wp-admin/includes/file.php</a></li>
<li><a href="#trunksrcwpadminincludesupdatecorephp">trunk/src/wp-admin/includes/update-core.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (25762 => 25763)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php        2013-10-11 03:16:59 UTC (rev 25762)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php   2013-10-11 16:05:13 UTC (rev 25763)
</span><span class="lines">@@ -213,7 +213,7 @@
</span><span class="cx">          if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
</span><span class="cx">                  $source = trailingslashit($source) . trailingslashit($source_files[0]);
</span><span class="cx">          elseif ( count($source_files) == 0 )
</span><del>-                       return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $this->strings['no_files'] ); //There are no files?
</del><ins>+                        return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
</ins><span class="cx">           else //It's only a single file, the upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
</span><span class="cx">                  $source = trailingslashit($source);
</span><span class="cx"> 
</span><span class="lines">@@ -262,7 +262,7 @@
</span><span class="cx">          //Create destination if needed
</span><span class="cx">          if ( !$wp_filesystem->exists($remote_destination) )
</span><span class="cx">                  if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
</span><del>-                               return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
</del><ins>+                                return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
</ins><span class="cx"> 
</span><span class="cx">          // Copy new version of item into place.
</span><span class="cx">          $result = copy_dir($source, $remote_destination);
</span><span class="lines">@@ -623,7 +623,7 @@
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          if ( ! $plugins_found )
</span><del>-                       return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('No valid plugins were found.') );
</del><ins>+                        return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
</ins><span class="cx"> 
</span><span class="cx">          return $source;
</span><span class="cx">  }
</span><span class="lines">@@ -989,16 +989,16 @@
</span><span class="cx"> 
</span><span class="cx">          // A proper archive should have a style.css file in the single subdirectory
</span><span class="cx">          if ( ! file_exists( $working_directory . 'style.css' ) )
</span><del>-                       return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
</del><ins>+                        return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], __( 'The theme is missing the <code>style.css</code> stylesheet.' ) );
</ins><span class="cx"> 
</span><span class="cx">          $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) );
</span><span class="cx"> 
</span><span class="cx">          if ( empty( $info['Name'] ) )
</span><del>-                       return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
</del><ins>+                        return new WP_Error( 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'], __( "The <code>style.css</code> stylesheet doesn't contain a valid theme header." ) );
</ins><span class="cx"> 
</span><span class="cx">          // If it's not a child theme, it must have at least an index.php to be legit.
</span><span class="cx">          if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) )
</span><del>-                       return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
</del><ins>+                        return new WP_Error( 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'], __( 'The theme is missing the <code>index.php</code> file.' ) );
</ins><span class="cx"> 
</span><span class="cx">          return $source;
</span><span class="cx">  }
</span><span class="lines">@@ -1141,7 +1141,7 @@
</span><span class="cx">          $remote_destination = $wp_filesystem->find_folder( WP_LANG_DIR );
</span><span class="cx">          if ( ! $wp_filesystem->exists( $remote_destination ) )
</span><span class="cx">                  if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) )
</span><del>-                               return new WP_Error( 'mkdir_failed', $this->strings['mkdir_failed'], $remote_destination );
</del><ins>+                                return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination );
</ins><span class="cx"> 
</span><span class="cx">          foreach ( $language_updates as $language_update ) {
</span><span class="cx"> 
</span><span class="lines">@@ -1200,7 +1200,7 @@
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          if ( ! $mo || ! $po )
</span><del>-                       return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'],
</del><ins>+                        return new WP_Error( 'incompatible_archive_pomo', $this->strings['incompatible_archive'],
</ins><span class="cx">                           __( 'The language pack is missing either the <code>.po</code> or <code>.mo</code> files.' ) );
</span><span class="cx"> 
</span><span class="cx">          return $source;
</span><span class="lines">@@ -1287,7 +1287,7 @@
</span><span class="cx">          // Copy update-core.php from the new version into place.
</span><span class="cx">          if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
</span><span class="cx">                  $wp_filesystem->delete($working_dir, true);
</span><del>-                       return new WP_Error('copy_failed', $this->strings['copy_failed']);
</del><ins>+                        return new WP_Error( 'copy_failed_for_update_core_file', $this->strings['copy_failed'] );
</ins><span class="cx">           }
</span><span class="cx">          $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunksrcwpadminincludesfilephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/file.php (25762 => 25763)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/file.php     2013-10-11 03:16:59 UTC (rev 25762)
+++ trunk/src/wp-admin/includes/file.php        2013-10-11 16:05:13 UTC (rev 25763)
</span><span class="lines">@@ -603,7 +603,7 @@
</span><span class="cx"> 
</span><span class="cx">  for ( $i = 0; $i < $z->numFiles; $i++ ) {
</span><span class="cx">          if ( ! $info = $z->statIndex($i) )
</span><del>-                       return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
</del><ins>+                        return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
</ins><span class="cx"> 
</span><span class="cx">          if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory
</span><span class="cx">                  continue;
</span><span class="lines">@@ -633,13 +633,13 @@
</span><span class="cx">  // Create those directories if need be:
</span><span class="cx">  foreach ( $needed_dirs as $_dir ) {
</span><span class="cx">          if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the Dir exists upon creation failure. Less I/O this way.
</span><del>-                       return new WP_Error('mkdir_failed', __('Could not create directory.'), $_dir);
</del><ins>+                        return new WP_Error( 'mkdir_failed_ziparchive', __( 'Could not create directory.' ), $_dir );
</ins><span class="cx">   }
</span><span class="cx">  unset($needed_dirs);
</span><span class="cx"> 
</span><span class="cx">  for ( $i = 0; $i < $z->numFiles; $i++ ) {
</span><span class="cx">          if ( ! $info = $z->statIndex($i) )
</span><del>-                       return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
</del><ins>+                        return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
</ins><span class="cx"> 
</span><span class="cx">          if ( '/' == substr($info['name'], -1) ) // directory
</span><span class="cx">                  continue;
</span><span class="lines">@@ -649,10 +649,10 @@
</span><span class="cx"> 
</span><span class="cx">          $contents = $z->getFromIndex($i);
</span><span class="cx">          if ( false === $contents )
</span><del>-                       return new WP_Error('extract_failed', __('Could not extract file from archive.'), $info['name']);
</del><ins>+                        return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] );
</ins><span class="cx"> 
</span><span class="cx">          if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) )
</span><del>-                       return new WP_Error('copy_failed', __('Could not copy file.'), $to . $info['name']);
</del><ins>+                        return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $to . $info['name'] );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  $z->close();
</span><span class="lines">@@ -691,7 +691,7 @@
</span><span class="cx">          return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true));
</span><span class="cx"> 
</span><span class="cx">  if ( 0 == count($archive_files) )
</span><del>-               return new WP_Error('empty_archive', __('Empty archive.'));
</del><ins>+                return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
</ins><span class="cx"> 
</span><span class="cx">  // Determine any children directories needed (From within the archive)
</span><span class="cx">  foreach ( $archive_files as $file ) {
</span><span class="lines">@@ -720,7 +720,7 @@
</span><span class="cx">  // Create those directories if need be:
</span><span class="cx">  foreach ( $needed_dirs as $_dir ) {
</span><span class="cx">          if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the dir exists upon creation failure. Less I/O this way.
</span><del>-                       return new WP_Error('mkdir_failed', __('Could not create directory.'), $_dir);
</del><ins>+                        return new WP_Error( 'mkdir_failed_pclzip', __( 'Could not create directory.' ), $_dir );
</ins><span class="cx">   }
</span><span class="cx">  unset($needed_dirs);
</span><span class="cx"> 
</span><span class="lines">@@ -733,7 +733,7 @@
</span><span class="cx">                  continue;
</span><span class="cx"> 
</span><span class="cx">          if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )
</span><del>-                       return new WP_Error('copy_failed', __('Could not copy file.'), $to . $file['filename']);
</del><ins>+                        return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $to . $file['filename'] );
</ins><span class="cx">   }
</span><span class="cx">  return true;
</span><span class="cx"> }
</span><span class="lines">@@ -766,12 +766,12 @@
</span><span class="cx">                          // If copy failed, chmod file to 0644 and try again.
</span><span class="cx">                          $wp_filesystem->chmod($to . $filename, 0644);
</span><span class="cx">                          if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
</span><del>-                                       return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
</del><ins>+                                        return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename );
</ins><span class="cx">                   }
</span><span class="cx">          } elseif ( 'd' == $fileinfo['type'] ) {
</span><span class="cx">                  if ( !$wp_filesystem->is_dir($to . $filename) ) {
</span><span class="cx">                          if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
</span><del>-                                       return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
</del><ins>+                                        return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename );
</ins><span class="cx">                   }
</span><span class="cx"> 
</span><span class="cx">                  // generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list
</span></span></pre></div>
<a id="trunksrcwpadminincludesupdatecorephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/update-core.php (25762 => 25763)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/update-core.php      2013-10-11 03:16:59 UTC (rev 25762)
+++ trunk/src/wp-admin/includes/update-core.php 2013-10-11 16:05:13 UTC (rev 25763)
</span><span class="lines">@@ -661,7 +661,7 @@
</span><span class="cx">  $versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php';
</span><span class="cx">  if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) {
</span><span class="cx">           $wp_filesystem->delete( $from, true );
</span><del>-                return new WP_Error( 'copy_failed', __('Could not copy file.') );
</del><ins>+                 return new WP_Error( 'copy_failed_for_version_file', __( 'Could not copy file.' ) );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  $wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE );
</span><span class="lines">@@ -741,10 +741,13 @@
</span><span class="cx">                  $total_size += filesize( $working_dir_local . '/' . $file ); 
</span><span class="cx"> 
</span><span class="cx">          // If we don't have enough free space, it isn't worth trying again
</span><del>-               if ( $total_size >= disk_free_space( ABSPATH ) )
</del><ins>+                if ( $total_size >= disk_free_space( ABSPATH ) ) {
</ins><span class="cx">                   $result = new WP_Error( 'disk_full', __( 'There is not enough free disk space to complete the update.' ), $to );
</span><del>-               else
</del><ins>+                } else {
</ins><span class="cx">                   $result = _copy_dir( $from . $distro, $to, $skip );
</span><ins>+                       if ( is_wp_error( $result ) )
+                               $result = new WP_Error( $result->get_error_code() . '_retry', $result->get_error_message(), $result->get_error_data() );
+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  // Custom Content Directory needs updating now.
</span><span class="lines">@@ -800,7 +803,7 @@
</span><span class="cx">                                          continue;
</span><span class="cx"> 
</span><span class="cx">                                  if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE) )
</span><del>-                                               $result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . $filename);
</del><ins>+                                                $result = new WP_Error( 'copy_failed_for_new_bundled', __( 'Could not copy file.' ), $dest . $filename );
</ins><span class="cx">                           } else {
</span><span class="cx">                                  if ( ! $development_build && $wp_filesystem->is_dir( $dest . $filename ) )
</span><span class="cx">                                          continue;
</span><span class="lines">@@ -887,12 +890,12 @@
</span><span class="cx">                          // If copy failed, chmod file to 0644 and try again.
</span><span class="cx">                          $wp_filesystem->chmod($to . $filename, 0644);
</span><span class="cx">                          if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
</span><del>-                                       return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
</del><ins>+                                        return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
</ins><span class="cx">                   }
</span><span class="cx">          } elseif ( 'd' == $fileinfo['type'] ) {
</span><span class="cx">                  if ( !$wp_filesystem->is_dir($to . $filename) ) {
</span><span class="cx">                          if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
</span><del>-                                       return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
</del><ins>+                                        return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );
</ins><span class="cx">                   }
</span><span class="cx"> 
</span><span class="cx">                  // generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list
</span></span></pre>
</div>
</div>

</body>
</html>