Index: release/package-release-nodes.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/release/package-release-nodes.php,v
retrieving revision 1.65
diff -u -F '^f' -u -F '^f' -r1.65 package-release-nodes.php
--- release/package-release-nodes.php	22 Apr 2010 22:12:23 -0000	1.65
+++ release/package-release-nodes.php	24 Apr 2010 02:14:21 -0000
@@ -260,6 +260,7 @@ function package_releases($type, $projec
     $project_short_name = escapeshellcmd($project_short_name);
     $version = escapeshellcmd($version);
     $tag = escapeshellcmd($tag);
+    $release_dir = '';
     db_query("DELETE FROM {project_release_package_errors} WHERE nid = %d", $nid);
     if ($release->rid == DRUPAL_CORE_REPOSITORY_ID) {
       $built = package_release_core($type, $nid, $project_short_name, $version, $tag);
@@ -274,6 +275,10 @@ function package_releases($type, $projec
       $num_built++;
       $project_nids[$pid] = TRUE;
     }
+    // Perform cleanup of failed builds.
+    else {
+      cleanup_failed_build($type, $nid, $project_short_name, $version, $tag, $release_dir);
+    }
     $num_considered++;
     if (count($wd_err_msg)) {
       db_query("INSERT INTO {project_release_package_errors} (nid, messages) values (%d, '%s')", $nid, serialize($wd_err_msg));
@@ -1231,3 +1236,46 @@ function core_make_file($core) {
 
   return $output;
 }
+
+/**
+ * Clean up any junk from failed builds.
+ *
+ * @param $type
+ *   The type of release, 'branch' or 'tag'.
+ * @param $nid
+ *   The node ID of the release.
+ * @param $project_short_name
+ *   {project_projects}.uri
+ * @param $version
+ *   Version string for the release.
+ * @param $tag
+ *   CVS tag for the release.
+ * @param $release_dir
+ *   The CVS directory path for the project (contrib only).
+ */
+function cleanup_failed_build($type, $nid, $project_short_name, $version, $tag, $release_dir) {
+  global $dest_root, $dest_rel;
+
+  $release_file_base_name = $dest_root . '/' . $dest_rel . '/' . $project_short_name . '-' . $version;
+  $base_tarball = $release_file_base_name . '.tar.gz';
+
+  // Remove the tarball generated from the CVS checkout.
+  if (file_exists($base_tarball)) {
+    unlink($base_tarball);
+  }
+
+  // For profiles, clean up any other profile-specific tarballs.
+  if (!empty($release_dir)) {
+    $parts = split('/', $release_dir);
+    // modules, themes, theme-engines, profiles, or translations
+    $contrib_type = $parts[1];
+    if ($contrib_type == 'profiles') {
+      foreach (array('no-core', 'core') as $type) {
+        $profile_tarball = "$release_file_base_name-$type.tar.gz";
+        if (file_exists($profile_tarball)) {
+          unlink($profile_tarball);
+        }
+      }
+    }
+  }
+}
