--- /temp/package-release-nodes.php Tue Sep 11 09:15:05 2007 +++ package-release-nodes.php Tue Sep 11 10:43:46 2007 @@ -83,6 +83,14 @@ define('SECURITY_UPDATE_TID', 100); // (Real work begins here, nothing else to customize) // ------------------------------------------------------------ +define ('EPERM', 1); +define ('ENOENT', 2); +define ('EACCES', 13); +define ('ENOTDIR', 20); +define ('EINVAL', 22); +define ('EBADMSG', 67); +define ('ECANCELLED', 256); + // Check if all required variables are defined $vars = array( 'drupal_root' => $drupal_root, @@ -167,6 +175,8 @@ elseif ($task == 'repair') { // ------------------------------------------------------------ function package_releases($type, $project_id) { + global $nid; + $nid = $project_id; if ($type == 'tag') { $where = " AND (prn.rebuild = 0) AND (prn.file_path = '')"; $plural = t('tags'); @@ -183,7 +193,7 @@ function package_releases($type, $projec } } else { - wd_err(t("ERROR: package_releases() called with unknown type: %type", array('%type' => $type))); + wd_err(EINVAL, t("ERROR: package_releases() called with unknown type: %type", array('%type' => $type))); return; } $args = array(); @@ -271,7 +281,7 @@ function package_release_core($nid, $uri // Fix any .info files foreach ($info_files as $file) { if (!fix_info_file_version($file, $uri, $version)) { - wd_err(t("ERROR: Failed to update version in %file, aborting packaging", array('%file' => $file)), $view_link); + wd_err(EPERM, t("ERROR: Failed to update version in %file, aborting packaging", array('%file' => $file)), $view_link); return false; } } @@ -326,7 +336,7 @@ function package_release_contrib($nid, $ return false; } if (!is_dir($fulldir)) { - wd_err(t("ERROR: %dir does not exist after cvs export %rev", array('%dir' => $fulldir, '%rev' => $rev)), $view_link); + wd_err(ENOENT, t("ERROR: %dir does not exist after cvs export %rev", array('%dir' => $fulldir, '%rev' => $rev)), $view_link); return false; } if (!drupal_chdir($basedir)) { @@ -349,7 +359,7 @@ function package_release_contrib($nid, $ // Fix any .info files foreach ($info_files as $file) { if (!fix_info_file_version($file, $uri, $version)) { - wd_err(t("ERROR: Failed to update version in %file, aborting packaging", array('%file' => $file)), $view_link); + wd_err(EPERM, t("ERROR: Failed to update version in %file, aborting packaging", array('%file' => $file)), $view_link); return false; } } @@ -391,7 +401,7 @@ function package_release_contrib($nid, $ } } else { - wd_err(t("ERROR: %uri translation does not contain a %uri_po file for version %version, not packaging", array('%uri' => $uri, '%uri_po' => "$uri.po", '%version' => $version)), $view_link); + wd_err(EINVAL, t("ERROR: %uri translation does not contain a %uri_po file for version %version, not packaging", array('%uri' => $uri, '%uri_po' => "$uri.po", '%version' => $version)), $view_link); return false; } } @@ -423,7 +433,8 @@ function package_release_contrib($nid, $ * Check that file metadata on disk matches the values stored in the DB. */ function verify_packages($task, $project_id) { - global $dest_root; + global $dest_root, $nid; + $nid = $project_id; $do_repair = $task == 'repair' ? TRUE : FALSE; $args = array(); $where = ''; @@ -460,7 +471,7 @@ function verify_packages($task, $project if (!is_file($full_path)) { $num_not_exist++; - wd_err(t('WARNING: %file does not exist.', array('%file' => $full_path)), $view_link); + wd_err(ENOENT, t('WARNING: %file does not exist.', array('%file' => $full_path)), $view_link); continue; } $real_date = filemtime($full_path); @@ -501,7 +512,7 @@ function verify_packages($task, $project $num_need_repair++; } else if (!db_query("UPDATE {project_release_nodes} SET file_hash = '%s', file_date = %d WHERE nid = %d", $real_hash, $real_date, $nid)) { - wd_err(t('ERROR: db_query() failed trying to update metadata for %file', array('%file' => $file_path)), $view_link); + wd_err(ECANCELED, t('ERROR: db_query() failed trying to update metadata for %file', array('%file' => $file_path)), $view_link); $num_failed++; } else { @@ -517,10 +528,10 @@ function verify_packages($task, $project '!num_wrong_hash' => $num_wrong_hash, ); if ($num_failed) { - wd_err(t('ERROR: unable to repair !num_failed releases due to db_query() failures.', array('!num_failed' => $num_failed))); + wd_err(ECANCELLED, t('ERROR: unable to repair !num_failed releases due to db_query() failures.', array('!num_failed' => $num_failed))); } if ($num_not_exist) { - wd_err(t('ERROR: !num_not_exist files are in the database but do not exist on disk.', array('!num_not_exist' => $num_not_exist))); + wd_err(ENOENT, t('ERROR: !num_not_exist files are in the database but do not exist on disk.', array('!num_not_exist' => $num_not_exist))); } if ($do_repair) { wd_check(t('Done checking releases: !num_repaired repaired, !num_wrong_date invalid dates, !num_wrong_hash invalid md5 hashes, !num_considered considered.', $num_vars)); @@ -551,7 +562,7 @@ function drupal_exec($cmd) { // Made sure we grab stderr, too... exec("$cmd 2>&1", $output, $rval); if ($rval) { - wd_err(t("ERROR: %cmd failed with status !rval", array('%cmd' => $cmd, '!rval' => $rval)) . '
' . implode("\n", array_map('htmlspecialchars', $output)));
+    wd_err(EBADMSG, t("ERROR: %cmd failed with status !rval", array('%cmd' => $cmd, '!rval' => $rval)) . '
' . implode("\n", array_map('htmlspecialchars', $output)));
     return false;
   }
   return true;
@@ -564,7 +575,7 @@ function drupal_exec($cmd) {
  */
 function drupal_chdir($dir) {
   if (!chdir($dir)) {
-    wd_err(t("ERROR: Can't chdir(@dir)", array('@dir' => $dir)));
+    wd_err(EPERM, t("ERROR: Can't chdir(@dir)", array('@dir' => $dir)));
     return false;
   }
   return true;
@@ -588,8 +599,12 @@ function wd_msg($msg, $link = NULL) {
 /**
  * Wrapper function for watchdog() to log error messages.
  */
-function wd_err($msg, $link = NULL) {
+function wd_err($errno, $msg, $link = NULL) {
+  global $nid;
   watchdog('package_error', $msg, WATCHDOG_ERROR, $link);
+  if isset($nid) {
+    db_query("INSERT INTO {project_release_package_errors} (`nid`,`errno`,`message`) values (%d, %d, %s)", $nid, $errno, $msg);
+  }
   echo $msg ."\n";
 }
 
@@ -613,7 +628,7 @@ function initialize_tmp_dir($task) {
   global $tmp_dir, $tmp_root;
 
   if (!is_dir($tmp_root)) {
-    wd_err(t("ERROR: tmp_root: @dir is not a directory", array('@dir' => $tmp_root)));
+    wd_err(ENOTDIR, t("ERROR: tmp_root: @dir is not a directory", array('@dir' => $tmp_root)));
     exit(1);
   }
 
@@ -623,7 +638,7 @@ function initialize_tmp_dir($task) {
     drupal_exec("$rm -rf $tmp_dir/*");
   }
   else if (!@mkdir($tmp_dir)) {
-    wd_err(t("ERROR: mkdir(@dir) failed", array('@dir' => $tmp_dir)));
+    wd_err(EPERM, t("ERROR: mkdir(@dir) failed", array('@dir' => $tmp_dir)));
     exit(1);
   }
 }
@@ -663,15 +678,15 @@ function fix_info_file_version($file, $u
   $info .= "\n";
 
   if (!chmod($file, 0644)) {
-    wd_err(t("ERROR: chmod(@file, 0644) failed", array('@file' => $file)));
+    wd_err(EPERM, t("ERROR: chmod(@file, 0644) failed", array('@file' => $file)));
     return false;
   }
   if (!$info_fd = fopen($file, 'ab')) {
-    wd_err(t("ERROR: fopen(@file, 'ab') failed", array('@file' => $file)));
+    wd_err(EACCES, t("ERROR: fopen(@file, 'ab') failed", array('@file' => $file)));
     return false;
   }
   if (!fwrite($info_fd, $info)) {
-    wd_err(t("ERROR: fwrite(@file) failed", array('@file' => $file)) . '
' . $info);
+    wd_err(EBADMSG, t("ERROR: fwrite(@file) failed", array('@file' => $file)) . '
' . $info);
     return false;
   }
   return true;