Index: modules/project/release/package-release-nodes.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/release/package-release-nodes.php,v retrieving revision 1.1.2.16 diff -u -p -r1.1.2.16 package-release-nodes.php --- modules/project/release/package-release-nodes.php 13 Nov 2006 04:27:22 -0000 1.1.2.16 +++ modules/project/release/package-release-nodes.php 13 Nov 2006 08:26:37 -0000 @@ -148,12 +148,10 @@ function package_releases($type) { if ($type == 'tag') { $where = " AND prn.rebuild = 0 AND (prn.file_path IS NULL OR prn.file_path = '')"; $plural = 'tags'; - $check_new = false; } elseif ($type == 'branch') { $where = " AND prn.rebuild = 1"; $plural = 'branches'; - $check_new = true; } else { watchdog('release_error', t("ERROR: package_releases() called with unknown type: %type", array('%type' => theme('placeholder', $type)))); @@ -173,13 +171,14 @@ function package_releases($type) { $rev = ($tag == 'TRUNK') ? '-r HEAD' : "-r $tag"; watchdog('release_package', t("Working on %type release: %id from $type: %tag", array('%type' => $release->rid == 1 ? t('core') : t('contrib'), '%id' => theme_placeholder($id), '%tag' => theme_placeholder($tag)))); $id = escapeshellcmd($id); + $version = escapeshellcmd($release->version); $rev = escapeshellcmd($rev); if ($release->rid == 1) { - $built = package_release_core($nid, $id, $rev, $check_new); + $built = package_release_core($nid, $id, $version, $rev); } else { $dir = escapeshellcmd($release->directory); - $built = package_release_contrib($nid, $id, $rev, $dir, $check_new); + $built = package_release_contrib($nid, $id, $version, $rev, $dir); } if ($built) { $num_built++; @@ -189,7 +188,7 @@ function package_releases($type) { watchdog('release_package', t("Done packaging releases from $plural: %num_built built, %num_considered considered.", array('%num_built' => $num_built, '%num_considered' => $num_considered))); } -function package_release_core($nid, $id, $rev, $check_new) { +function package_release_core($nid, $id, $version, $rev) { global $tmp_dir, $repositories, $dest_root, $dest_rel; global $cvs, $tar, $gzip, $rm; $rid = 1; @@ -210,7 +209,23 @@ function package_release_core($nid, $id, return false; } - // TODO: do we even care about $check_new? The old script didn't... + $info_files = array(); + $exclude = array('.', '..', 'LICENSE.txt'); + $youngest = file_find_youngest($id, 0, $exclude, $info_files); + if (is_file($full_dest) && filectime($full_dest) + 300 > $youngest) { + // The existing tarball for this release is newer than the youngest + // file in the directory, we're done. + watchdog('release_package', t("%id is unchanged, not re-packaging", array('%id' => theme('placeholder', $id)))); + return false; + } + + // Fix any .info files + foreach ($info_files as $file) { + if (!fix_info_file_version($file, $version)) { + watchdog('release_error', t("ERROR: Failed to update version in %file, aborting packaging", array('%file' => $file))); + return false; + } + } if (!drupal_exec("$tar -c --file=- $id | $gzip -9 --no-name > $full_dest")) { return false; @@ -224,7 +239,7 @@ function package_release_core($nid, $id, return true; } -function package_release_contrib($nid, $id, $rev, $dir, $check_new) { +function package_release_contrib($nid, $id, $version, $rev, $dir) { global $tmp_dir, $repositories, $dest_root, $dest_rel; global $cvs, $tar, $gzip, $rm, $ln; global $msgcat, $msgattrib, $msgfmt; @@ -256,7 +271,10 @@ function package_release_contrib($nid, $ if (!drupal_exec("$cvs -q export $rev $fulldir")) { return false; } - + if (!is_dir($fulldir)) { + watchdog('release_error', t("ERROR: %dif does not exist after cvs export %rev", array('%dir' => theme('placeholder', $fulldir), '%rev' => theme('placeholder', $rev)))); + return false; + } if (!drupal_chdir($basedir)) { // TODO: try to clean up the cvs export we just did? // seems scary if we can't even chdir($basedir)... @@ -266,12 +284,19 @@ function package_release_contrib($nid, $ if ($contrib_type == 'translations') { $exclude = array_merge($exclude, 'README.txt'); } - if (is_file($full_dest) && $check_new) { - $youngest = file_find_youngest($uri, 0, $exclude); - if (filectime($full_dest) + 300 > $youngest) { - // The existing tarball for this release is newer than the youngest - // file in the directory, we're done. - watchdog('release_package', t("%id is unchanged, not re-packaging", array('%id' => theme('placeholder', $id)))); + $info_files = array(); + $youngest = file_find_youngest($uri, 0, $exclude, $info_files); + if (is_file($full_dest) && filectime($full_dest) + 300 > $youngest) { + // The existing tarball for this release is newer than the youngest + // file in the directory, we're done. + watchdog('release_package', t("%id is unchanged, not re-packaging", array('%id' => theme('placeholder', $id)))); + return false; + } + + // Fix any .info files + foreach ($info_files as $file) { + if (!fix_info_file_version($file, $version)) { + watchdog('release_error', t("ERROR: Failed to update version in %file, aborting packaging", array('%file' => $file))); return false; } } @@ -409,6 +434,46 @@ function initialize_repository_info() { } } + +/** + * Fix the given .info file with the specified version string + */ +function fix_info_file_version($file, $version) { + $new_file = "$file.new"; + $new_fd = fopen($new_file, 'wb'); + if (!$new_fd) { + watchdog('release_error', t("ERROR: fopen(%file, 'wb') failed", array('%file' => $new_file))); + return false; + } + $old_fd = fopen($file, 'rb'); + if (!$old_fd) { + watchdog('release_error', t("ERROR: fopen(%file, 'rb') failed", array('%file' => $file))); + return false; + } + $saw_version = false; + while (!feof($old_fd)) { + $line = fgets($old_fd, 4096); + if (preg_match('/^version/i', $line)) { + $line = "version = \"$version\"\n"; + $saw_version = true; + } + fwrite($new_fd, $line); + } + if (!$saw_version) { + $line = "version = \"$version\"\n"; + fwrite($new_fd, $line); + } + fclose($old_fd); + fclose($new_fd); + unlink($file); + if (!rename($new_file, $file)) { + watchdog('release_error', t("ERROR: rename(%new_file, %file) failed", array('%new_file' => $new_file, '%file' => $file))); + return false; + } + return true; +} + + /** * Update the DB with the new file info for a given release node. */ @@ -429,16 +494,19 @@ function package_release_update_node($ni * Find the youngest (newest) file in a directory tree. * Stolen wholesale from the original package-drupal.php script. */ -function file_find_youngest($dir, $timestamp, $exclude) { +function file_find_youngest($dir, $timestamp, $exclude, &$info_files) { if (is_dir($dir)) { $fp = opendir($dir); while (FALSE !== ($file = readdir($fp))) { if (!in_array($file, $exclude)) { if (is_dir("$dir/$file")) { - $timestamp = file_find_youngest("$dir/$file", $timestamp, $exclude); + $timestamp = file_find_youngest("$dir/$file", $timestamp, $exclude, $info_files); } else { $timestamp = (filectime("$dir/$file") > $timestamp) ? filectime("$dir/$file") : $timestamp; + if (preg_match('/^.+\.info$/', $file)) { + $info_files[] = "$dir/$file"; + } } } }