889633f4b77694a53dcca81fb28cdd07f4db297b
hiram
  Wed Aug 12 15:54:36 2026 -0700
make the cleanup step safe for rerun == idempotent refs #38005

diff --git src/hg/utils/automation/doNcbiGene.pl src/hg/utils/automation/doNcbiGene.pl
index 9a527a04d04..03884e5e025 100755
--- src/hg/utils/automation/doNcbiGene.pl
+++ src/hg/utils/automation/doNcbiGene.pl
@@ -376,32 +376,42 @@
   $bossScript->execute();
 
   # reached only if the boss script above exited 0 -- the new build is
   # complete and validated under *.new file names, so it is now safe to
   # archive the previous live version and promote the new one into place
   archivePriorVersion();
   promoteNewBuild();
 } # doNcbiGene
 
 #########################################################################
 # * step: cleanup [fileServer]
 sub doCleanup {
   my $whatItDoes = "compress intermediate files";
   my $bossScript = new HgRemoteScript("$buildDir/doCleanup.csh", $fileServer,
 				      $buildDir, $whatItDoes);
+  # guard each file individually -- this step has no needsUpdate() check
+  # of its own, so it can be re-run (e.g. by the outer driver script) on
+  # a later invocation where ncbiGene did nothing new; by then these are
+  # already $file.gz from the previous successful cleanup, and a plain
+  # 'gzip -f' on a now-missing plain-named file would die under this
+  # script's 'csh -e'
   $bossScript->add(<<_EOF_
-gzip -f $db.geneAttrs.ncbi.txt $db.ncbiGene.log.txt $db.ncbiGene.bed
+foreach f ( $db.geneAttrs.ncbi.txt $db.ncbiGene.log.txt $db.ncbiGene.bed )
+  if ( -e \$f ) then
+    gzip -f \$f
+  endif
+end
 _EOF_
   );
   $bossScript->execute();
 } # doCleanup
 
 #########################################################################
 # main
 
 &HgAutomate::closeStdin();
 
 &checkOptions();
 &usage(1) if (scalar(@ARGV) != 2);
 
 $secondsStart = `date "+%s"`;
 chomp $secondsStart;