356b5d16ef911e6ab8935233750d6c74297ab5db
larrym
  Mon Sep 19 14:27:58 2011 -0700
make sure file exists before deleting it (can happen b/c of loop over two destFiles)
diff --git src/hg/utils/cpAndLinkToResourceFiles.pl src/hg/utils/cpAndLinkToResourceFiles.pl
index 9da1e49..9ea1bf6 100755
--- src/hg/utils/cpAndLinkToResourceFiles.pl
+++ src/hg/utils/cpAndLinkToResourceFiles.pl
@@ -162,33 +162,33 @@
             $versionedFile =~ s/\.$suffix$/-v$cgiVersion.$suffix/;
             for my $destFile ($file, $versionedFile) {
                 my $update = 0;
                 my $exists = 0;
                 if(-e $destFile) {
                     my @destStat = stat("$destFile") or die "Couldn't stat '$destFile'; err: $!";
                     $update = ($destStat[9] < $mtime);
                     $exists = 1;
                 } else {
                     $update = 1;
                 }
                 $update = $update || $force;
                 if($update) {
                     # delete obsolete files
                     for my $f (@destFiles) {
-                        if($f =~ /^$prefix-v\d+\.$suffix$/) {
+                        if(-e $f && $f =~ /^$prefix-v\d+\.$suffix$/) {
                             if($f ne $destFile) {
-                                print STDERR "Deleting old version of file $file\n" if($debug);
+                                print STDERR "Deleting old version of file $file: '$f'\n" if($debug);
                                 unlink($f) || die "Couldn't unlink obsolete versioned file '$f'; err: $!";
                             }
                         }
                     }
                     if($exists) {
                         unlink($destFile) || die "Couldn't unlink '$destFile'";
                     }
                     if($minify && $suffix eq 'js') {
                         my $cmd = "/usr/bin/java -jar $minifyJar $srcFile -o $destFile";
                         print STDERR "cmd: $cmd\n" if($debug);
                         !system($cmd) || die "Couldn't run cmd '$cmd': err: $!";
                     } else {
                         my $cmd = "cp -p $srcFile $destFile";
                         print STDERR "cmd: $cmd\n" if($debug);
                         !system($cmd) || die "Couldn't $cmd; err: $!";
