Index: trunk/pstamp/scripts/pstamp_job_run.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_job_run.pl	(revision 30528)
+++ trunk/pstamp/scripts/pstamp_job_run.pl	(revision 30529)
@@ -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 );
@@ -155,10 +155,6 @@
             # Try and replace the streaks from the recovery images
 
-            @file_list = ();
-            $tmproot = "$outdir/$job_id";
-            if (! -e $tmproot) {
-                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
@@ -166,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
@@ -231,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";
