Index: /tags/ipp-20101215/pstamp/scripts/pstamp_job_run.pl
===================================================================
--- /tags/ipp-20101215/pstamp/scripts/pstamp_job_run.pl	(revision 30541)
+++ /tags/ipp-20101215/pstamp/scripts/pstamp_job_run.pl	(revision 30542)
@@ -14,5 +14,5 @@
 use File::Basename;
 use File::Copy;
-use File::Temp qw(tempfile);
+use File::Temp qw(tempfile tempdir);
 use Digest::MD5::File qw( file_md5_hex );
 use PS::IPP::PStamp::RequestFile qw( :standard );
@@ -144,6 +144,10 @@
         } elsif (($options & $PSTAMP_REQUIRE_UNCENSORED) and ($stage ne 'chip')) {
             # user required uncensored but since stage isn't chip we can't rebuild them
-            my_die("uncensored inputs not available for job $job_id", $job_id, $PSTAMP_NOT_AVAILABLE);
-        } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($stage ne 'chip')) {
+            my_die("uncensored inputs not available for job $job_id", $job_id, $PSTAMP_NOT_AVAILABLE, 'stop');
+        } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($params->{state} eq 'update') and ($stage ne 'chip')) {
+            # we can only restore pixels for chip stage images if the data has been updated.
+            # XXX: this test is not quite good enough. If all components have been updated then the
+            # state will be 'full' But this will get us going.
+            print "Run state is update: will make stamps from destreaked $stage images.\n";
             # make stamps from uncensored images
             $muggle = 0;
@@ -151,8 +155,6 @@
             # Try and replace the streaks from the recovery images
 
-            @file_list = ();
-            $tmproot = "$outdir/$job_id";
-            mkdir $tmproot or
-                my_die( "failed to create temporary directory $tmproot", $job_id, $PS_EXIT_UNKNOWN_ERROR);
+            my $temp_dir = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR") or &my_die("Unable to find temporary directory in site configuration", $job_id, $PS_EXIT_CONFIG_ERROR);
+            $tmproot = tempdir("$temp_dir/psjob.$job_id.XXXX", CLEANUP => !$save_temps);
             my $muggle_command = "$streaksreplace -stage $stage -tmproot $tmproot";
             # find the "directory" of the input path_base
@@ -160,4 +162,6 @@
             my $base = basename($image);
             $tmpImage = "$tmproot/$base";
+
+            @file_list = ();
 
             # XXX: We should get the recovery_path_base from the magicDSFile but that requires a bunch of file rule and
@@ -180,5 +184,5 @@
                 $base = basename($variance);
                 $tmpVariance = "$tmproot/$base";
-                $newFileArgs .= " -weight $tmpVariance";
+                $newFileArgs .= " -variance $tmpVariance";
                 my $recVariance = "$inputdir/REC_$base";
                 $muggle_command .= " -weight $variance -recweight $recVariance";
@@ -225,11 +229,4 @@
     }
 
-    if (!$save_temps) {
-        unlink $tmpImage if $tmpImage;
-        unlink $tmpMask if $tmpMask;
-        unlink $tmpVariance if $tmpVariance;
-        rmdir $tmproot if $tmproot;
-    }
-
     if ($exitStatus == 0) {
         my $reglist = "$outdir/reglist$job_id";
