Index: /branches/eam_branches/ipp-20110213/PS-IPP-Config/lib/PS/IPP/Config.pm
===================================================================
--- /branches/eam_branches/ipp-20110213/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 30676)
@@ -1148,43 +1148,10 @@
     if ($neb->storage_object_exists($output)) {
         if ($delete_existing) {
-            # avoid dead instances by moving the file before deleting it.
-            # append current time to form new name
-            my $todelete;
-            eval {
-                # parse the key so that we can compute the new name
-                require Nebulous::Key;
-            };
-            if ($@) {
-                carp "Can't find Nebulous::Key";
-                $$r_error = $PS_EXIT_CONFIG_ERROR;
-                return undef;
-            }
-            eval {
-                # parse the key so that we can compute the new name
-                my $neb_key = Nebulous::Key::parse_neb_key($output);
-                die "parse_neb_key failed" if !$neb_key;
-                my $path = $neb_key->path;
-                die "neb_key has no path" if !$path;
-                my $ticks = time();
-                $todelete = "ipp_trash/$path.$ticks";
-                $neb->move($output, $todelete);
-            };
-            if ($@) {
-                carp "nebulous move failed for $output";
+            $$r_error = $self->_kill_nebulous_file($output);
+            if ($$r_error) {
                 $output = undef;
-                $$r_error = $PS_EXIT_SYS_ERROR;
-            }
-            if ($todelete) {
-                eval {
-                    $neb->delete($todelete);
-                };
-                if ($@) {
-                    carp "nebulous delete for $todelete failed. Ignoring.\n";
-                    $$r_error = $PS_EXIT_SYS_ERROR;
-                }
             }
         } else {
             # Make sure that there is only 1 instance.
-
             eval {
                 $neb->there_can_be_only_one($output);
@@ -1198,4 +1165,77 @@
     }
     return $output;
+}
+
+# _kill_nebulous_file: reliably get a nebulous file out of way.
+# First move it to the trash then attempt to delete it. No failure if delete fails.
+# The file is in the trash.
+# Assumes that file is a nebulous file with a storage object that exists
+# Users should call kill_file()
+# Returns 0 on success otherwise and a PS_EXIT error code on failure
+sub _kill_nebulous_file {
+    my $self = shift;
+    my $filename = shift;
+    my $neb = $self->nebulous;
+
+    # avoid dead instances by moving the file before deleting it.
+    # append current time to form new name
+    my $todelete;
+    eval {
+        # parse the key so that we can compute the new name
+        require Nebulous::Key;
+    };
+    if ($@) {
+        carp "Can't find Nebulous::Key";
+        return $PS_EXIT_CONFIG_ERROR;
+    }
+    eval {
+        # parse the key so that we can compute the new name
+        my $neb_key = Nebulous::Key::parse_neb_key($filename);
+        die "parse_neb_key failed" if !$neb_key;
+        my $path = $neb_key->path;
+        die "neb_key has no path" if !$path;
+        my $ticks = time();
+        $todelete = "ipp_trash/$path.$ticks";
+        $neb->move($filename, $todelete);
+    };
+    if ($@) {
+        carp "nebulous move failed for $filename";
+        return $PS_EXIT_SYS_ERROR;
+    }
+    if ($todelete) {
+        eval {
+            $neb->delete($todelete);
+        };
+        if ($@) {
+            carp "nebulous delete for $todelete failed. Ignoring.\n";
+            return $PS_EXIT_SYS_ERROR;
+        }
+    }
+    return 0;
+}
+
+# user level interface to kill_file reliably get a file out of way.
+#
+# If a nebulous file, move it to the trash then attempt to delete it. 
+# if non nebulous file just delete it.
+# Returns 0 on success otherwise and a PS_EXIT error code on failure
+
+sub kill_file {
+    my $self = shift;
+    my $filename = shift;
+    my $neb = $self->nebulous;
+
+    my $scheme = file_scheme($filename);
+    if (!$scheme or ($scheme ne 'neb')) {
+        if ($self->file_exists($filename)) {
+            if (!$self->file_delete($filename)) {
+                carp "failed to delete $filename";
+                return $PS_EXIT_SYS_ERROR;
+            }
+        }
+    } elsif ($neb->storage_object_exists($filename)) {
+        $self->_kill_nebulous_file($filename);
+    }
+    return 0;
 }
 
Index: /branches/eam_branches/ipp-20110213/ippScripts/scripts/dist_bundle.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/ippScripts/scripts/dist_bundle.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippScripts/scripts/dist_bundle.pl	(revision 30676)
@@ -287,5 +287,7 @@
         # we can use the chip mask because disttool demands that magic have been run
         # and so the camera mask and the chip mask are the same
-        $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $chip_path_base, $component);
+        #$mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $chip_path_base, $component);
+        # XXX: hack the pending query passes in the camera path base
+        $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $chip_path_base, $component);
         my $mask_resolved = $ipprc->file_resolve($mask);
         my $fh = open_with_retries($mask_resolved);
Index: /branches/eam_branches/ipp-20110213/ippScripts/scripts/ipp_cleanup.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/ippScripts/scripts/ipp_cleanup.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippScripts/scripts/ipp_cleanup.pl	(revision 30676)
@@ -1900,36 +1900,12 @@
 {
     my $files = shift; # reference to a list of files to unlink
-#     my $test_verbose = 1;
-
-#     if ($test_verbose == 1) {
-#       open(TMPLOG,">>/tmp/czw.cleanup.log");
-#       flock(TMPLOG,2);
-#     }
-
-    # this script is, of course, very dangerous.
+
     foreach my $file (@$files) {
         print STDERR "unlinking $stage $stage_id $file";
-        unless ($ipprc->file_exists($file)) {
-            print STDERR "\t File not found\n";
-        }
-        else {
-            print STDERR "\n";
-        }
-
-#       if ($test_verbose == 1) {
-#           print TMPLOG "$stage $stage_id $file";
-
-#           else {
-#               print TMPLOG "\n";
-#           }
-#       }
-
-        $ipprc->file_delete($file);
-    }
-
-#     if ($test_verbose == 1) {
-#       flock(TMPLOG,8);
-#       close(TMPLOG);
-#     }
+
+        my $error_code = $ipprc->kill_file($file);
+
+        &my_die("failed to kill $file", $stage, $stage_id, $PS_EXIT_CONFIG_ERROR) if $error_code;
+    }
 
     return 1;
Index: /branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_cleanup.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 30676)
@@ -44,5 +44,5 @@
            'magic_ds_id=s'  => \$magic_ds_id,# Magic destreak run identifier
            'camera=s'       => \$camera,     # camera for evaluating file rules
-           'stage=s'        => \$stage,     # camera for evaluating file rules
+           'stage=s'        => \$stage,      # ipp stage for this magicDSRun
            'save-temps'     => \$save_temps, # Save temporary files?
            'dbname=s'       => \$dbname,     # Database name
@@ -160,5 +160,5 @@
         my $backup_path_base = $comp->{backup_path_base};
         my ($bimage, $bmask, $bch_mask, $bweight, $bsources, $bastrom);
-        my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom);
+#        my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom);
 
         if ($stage eq "chip") {
@@ -219,5 +219,5 @@
         }
 
-        delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask, $rch_mask);
+        delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask);
 
         if ($stage eq "diff" and $warp_warp) {
@@ -252,14 +252,6 @@
     foreach my $file (@_) {
         if ($file) {
-            if ($ipprc->file_exists($file)) {
-                if (!$no_update) {
-                    print STDERR "deleting $file\n" if $verbose;
-                    $ipprc->file_delete($file, 1) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR);
-                    } else {
-                    print STDERR "skipping delete $file\n";
-                }
-            } else {
-                print STDERR "$file not found\n" if $verbose;
-            }
+            my $error_code = $ipprc->kill_file($file);
+            my_die("Failed to delete $file", $magic_ds_id, $error_code) if $error_code;
         }
     }
Index: /branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_revert.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_revert.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_revert.pl	(revision 30676)
@@ -191,5 +191,5 @@
     # Note that when destreaking as part of an update $magicked is non-zero.
     # In this case we do not touch the camera stage mask so there is no need to revert it
-    if (!$magicked and $dynamicMasks) {
+    if ($dynamicMasks and (!$magicked or ($run_state eq 'goto_restored'))) {
         $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);
         $ch_mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
@@ -210,9 +210,11 @@
     $bweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $backup_path_base, $class_id);
 
-    $rimage  = $ipprc->filename("PPIMAGE.CHIP", $recovery_path_base, $class_id);
-    # This is somewhat kludgey but it works whether the mask is camera mask or chip mask
-    $rmask   = dirname($recovery_path_base) . "/REC_" . basename($mask);
-    $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $class_id);
-    $rweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $recovery_path_base, $class_id);
+    if ($recovery_path_base) {
+        $rimage  = $ipprc->filename("PPIMAGE.CHIP", $recovery_path_base, $class_id);
+        # This is somewhat kludgey but it works whether the mask is camera mask or chip mask
+        $rmask   = dirname($recovery_path_base) . "/REC_" . basename($mask);
+        $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $class_id);
+        $rweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $recovery_path_base, $class_id);
+    }
 } elsif ($stage eq "camera") {
     $astrom =  $ipprc->filename("PSASTRO.OUTPUT", $path_base);
@@ -227,7 +229,9 @@
     $bweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $backup_path_base);
     $bsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $backup_path_base);
-    $rimage  = $ipprc->filename("PSWARP.OUTPUT", $recovery_path_base);
-    $rmask   = $ipprc->filename("PSWARP.OUTPUT.MASK", $recovery_path_base);
-    $rweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $recovery_path_base);
+    if ($recovery_path_base) {
+        $rimage  = $ipprc->filename("PSWARP.OUTPUT", $recovery_path_base);
+        $rmask   = $ipprc->filename("PSWARP.OUTPUT.MASK", $recovery_path_base);
+        $rweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $recovery_path_base);
+    }
 } elsif ($stage eq "diff") {
     my $name = "PPSUB.OUTPUT";
Index: /branches/eam_branches/ipp-20110213/ippScripts/scripts/receive_file.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/ippScripts/scripts/receive_file.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippScripts/scripts/receive_file.pl	(revision 30676)
@@ -41,5 +41,5 @@
 
 # Parse the command-line arguments
-my ( $file_id, $source, $product, $fileset, $fileset_id, $file, $component, $bytes, $md5sum, $workdir, $dirinfo_uri, $dbname, $verbose, $no_update, $save_temps );
+my ( $file_id, $source, $product, $fileset, $fileset_id, $file, $component, $bytes, $md5sum, $workdir, $dirinfo_uri, $no_extract, $dbname, $verbose, $no_update, $save_temps );
 
 GetOptions(
@@ -54,4 +54,5 @@
            'md5sum=s'          => \$md5sum, # md5sum for file from data store
            'workdir=s'         => \$workdir, # Working directory for output
+           'no-extract'        => \$no_extract, # Do not extract the tarfiles
            'dirinfo=s'    => \$dirinfo_uri, # file containing the destination directories for this component
            'dbname=s'          => \$dbname,    # Database name
@@ -85,8 +86,26 @@
 my $mdcParser = PS::IPP::Metadata::Config->new;
 
-
+# select a directory for the dirinfo and dbinfo files
+# XXX: perhaps this directory should be set by the script and passed in
+# rather than computed here.
+
+my ($day, $month, $year) = (localtime)[3,4,5];
+my $datestr = sprintf "%04d%02d%02d", $year+1900, $month + 1, $day;
+my $dir_for_info_files = caturi($workdir, $datestr, $fileset);
+
+
+my $is_tarfile = 0;
+if ($file =~ m|.*\.tgz$|) {        # XXX: perhaps get this off of file type ?
+    $is_tarfile = 1;
+}
+
+my $filename;
+if ($is_tarfile and $no_extract) {
+    $filename = "$dir_for_info_files/$file"; 
+} else {
+    $filename = "$tempdir/$file";
+}
 
 # Retrieve file
-my $filename = "$tempdir/$file";  # Target filename
 {
     my $uri = "$source/$product/$fileset/$file"; # URI for datastore file
@@ -107,11 +126,4 @@
 my ($destdir, $components, $dirinfo_lines) = read_dirinfo_file($dirinfo_file_to_read, $file_id);
 
-# select a directory for the dirinfo and dbinfo files
-# XXX: perhaps this directory should be set by the script and passed in
-# rather than computed here.
-
-my ($day, $month, $year) = (localtime)[3,4,5];
-my $datestr = sprintf "%04d%02d%02d", $year+1900, $month + 1, $day;
-my $dir_for_info_files = caturi($workdir, $datestr, $fileset);
 
 # Deal with file
@@ -279,5 +291,5 @@
 
 
-} elsif ($file =~ m|.*\.tgz$|) {        # XXX: perhaps get this off of file type ?
+} elsif ($is_tarfile and !$no_extract) {
     # Get contents of tarball
     my @files = ();
@@ -339,4 +351,6 @@
         }
     }
+} elsif ($is_tarfile and $no_extract) {
+    print "skipping extraction of tarfile $filename\n";
 } else {
     &my_die( "Unrecognised file: $file\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
Index: /branches/eam_branches/ipp-20110213/ippScripts/scripts/register_imfile.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/ippScripts/scripts/register_imfile.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippScripts/scripts/register_imfile.pl	(revision 30676)
@@ -199,4 +199,8 @@
     $command .= " -data_state full";
 }
+elsif (is_ccim($tmp_exp_name,$exp_type)) {
+    printf STDERR "This is a camera commanded detrend exposure that should not cause a burn.\n";
+    $command .= " -data_state full";
+}    
 else {
     printf STDERR "Need to check burntool.\n";
@@ -380,4 +384,20 @@
 }
 
+sub is_ccim 
+{
+    my $exp_name = shift;
+    my $exp_type = shift;
+ 
+    # needs to match regtool.c checks for "is_ccim".
+    if ($exp_name =~ /c/) {
+	if (($exp_type eq 'DOMEFLAT')||
+	    ($exp_type eq 'DARK')||
+	    ($exp_type eq 'BIAS')) {
+	    return(1);
+	}
+    }
+    return(0);
+}
+
 sub is_daytime
 {
Index: /branches/eam_branches/ipp-20110213/ippScripts/scripts/stack_skycell.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/ippScripts/scripts/stack_skycell.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippScripts/scripts/stack_skycell.pl	(revision 30676)
@@ -172,5 +172,9 @@
 my $photometry = metadataLookupBool($recipe, 'PHOTOMETRY'); # perform photometry?
 my $output_nocomp = metadataLookupBool($recipe, 'OUTPUT.NOCOMP'); # change filerules to produced uncompressed output images
-
+my $output_logflux = metadataLookupBool($recipe, 'OUTPUT.LOGFLUX'); # change filerules to produce logflux compressed output images.
+
+if ($output_nocomp and $output_logflux) {
+    &my_die("Unable to not compress and logflux compress simultaneously. Check config.",$stack_id, $PS_EXIT_CONFIG_ERROR);
+}
 
 # Generate MDC file with the inputs
@@ -252,4 +256,12 @@
         $command .= " -F PPSTACK.UNCONV.EXPWT PPSTACK.UNCONV.EXPWT.NOCOMP";
     }
+    if ($output_logflux) {
+	$command .= " -R PPSTACK.OUTPUT FITS.TYPE COMP_STACK "; # Just this one output component?
+	$command .= " -R PPSTACK.OUTPUT.VARIANCE FITS.TYPE COMP_STACK "; 
+	$command .= " -R PPSTACK.OUTPUT.EXPWT FITS.TYPE COMP_STACK ";
+	$command .= " -R PPSTACK.UNCONV FITS.TYPE COMP_STACK ";
+	$command .= " -R PPSTACK.UNCONV.VARIANCE FITS.TYPE COMP_STACK ";
+	$command .= " -R PPSTACK.UNCONV.EXPWT FITS.TYPE COMP_STACK ";
+    }
     $command .= " -threads $threads" if defined $threads;
     $command .= " -debug-stack" if defined $debug;
Index: /branches/eam_branches/ipp-20110213/ippTasks/destreak.pro
===================================================================
--- /branches/eam_branches/ipp-20110213/ippTasks/destreak.pro	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippTasks/destreak.pro	(revision 30676)
@@ -395,4 +395,5 @@
     book getword magicDSToRevert $pageName component -var COMPONENT
     book getword magicDSToRevert $pageName path_base -var PATH_BASE
+    book getword magicDSToRevert $pageName recovery_path_base -var RECOVERY_PATH_BASE
     book getword magicDSToRevert $pageName cam_path_base -var CAM_PATH_BASE
     book getword magicDSToRevert $pageName cam_reduction -var CAM_REDUCTION
@@ -416,5 +417,5 @@
     end
 
-    $run = magic_destreak_revert.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $OUTROOT --logfile $logfile --replace $REPLACE --bothways $BOTHWAYS --magicked $MAGICKED --run-state $RUN_STATE
+    $run = magic_destreak_revert.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $OUTROOT --logfile $logfile --replace $REPLACE --bothways $BOTHWAYS --magicked $MAGICKED --run-state $RUN_STATE --recovery_path_base $RECOVERY_PATH_BASE
 
     add_standard_args run
Index: /branches/eam_branches/ipp-20110213/ippTasks/diskbalance.pro
===================================================================
--- /branches/eam_branches/ipp-20110213/ippTasks/diskbalance.pro	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippTasks/diskbalance.pro	(revision 30676)
@@ -183,5 +183,6 @@
         break
     end
-#    periods -exec 3
+    # Reset the speed if we're doing something
+    periods -exec 0.5
 
     # look for new objects in balancePending
Index: /branches/eam_branches/ipp-20110213/ippTasks/dist.pro
===================================================================
--- /branches/eam_branches/ipp-20110213/ippTasks/dist.pro	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippTasks/dist.pro	(revision 30676)
@@ -178,6 +178,6 @@
   host         local
 
-  periods      -poll 20
-  periods      -exec $LOADEXEC
+  periods      -exec 20
+  periods      -poll $LOADPOLL
   periods      -timeout 300
   npending     1
Index: /branches/eam_branches/ipp-20110213/ippTasks/receive.pro
===================================================================
--- /branches/eam_branches/ipp-20110213/ippTasks/receive.pro	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/ippTasks/receive.pro	(revision 30676)
@@ -105,4 +105,16 @@
 $receive_Advance_DB = 0
 
+# set this to skip extraction of tarfiles into their destination directories
+$NO_EXTRACT = ""
+macro set.no.extract
+    $NO_EXTRACT = "--no-extract"
+end
+macro clear.no.extract
+    $NO_EXTRACT = ""
+end
+macro show.no.extract
+    echo $NO_EXTRACT
+end
+
 task	       receive.source.load
   host         local
@@ -416,5 +428,5 @@
     host anyhost
 
-    $run = receive_file.pl --file_id $FILE_ID --source $SOURCE --product $PRODUCT --fileset $FILESET --fileset_id $FILESET_ID --file $FILE --component $COMPONENT --bytes $BYTES --md5 $MD5SUM --workdir $WORKDIR --dirinfo $DIRINFO
+    $run = receive_file.pl --file_id $FILE_ID --source $SOURCE --product $PRODUCT --fileset $FILESET --fileset_id $FILESET_ID --file $FILE --component $COMPONENT --bytes $BYTES --md5 $MD5SUM --workdir $WORKDIR --dirinfo $DIRINFO $NO_EXTRACT
     add_standard_args run
 
Index: /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_checkdependent.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_checkdependent.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_checkdependent.pl	(revision 30676)
@@ -193,12 +193,15 @@
 
     if (!$job_fault and ($stage eq 'chip')) {
-        # should only get here with data_state 'full' and perhaps destreaking not done
-        my_die ("Unexpected state for ${stage}Run $stage_id $state", $PS_EXIT_PROG_ERROR)
-            if $it->{data_state} ne 'full';
-
-        # chip processing is done, start destreaking.
-        my @chips;
-        push @chips, $it->{class_id};
-        $job_fault = check_states_magicDSRun($stage, $stage_id, \@chips, $rlabel, $need_magic, $it->{raw_magicked}, $it->{magic_ds_id}, $it->{dsRun_state});
+        # what about "error_cleaned" ?
+        if (! ($it->{data_state} =~ /cleaned/) ) {
+            # should only get here with data_state 'full' and perhaps destreaking not done
+            my_die ("Unexpected state for ${stage}Run $stage_id $state", $PS_EXIT_PROG_ERROR)
+                if $it->{data_state} ne 'full';
+
+            # chip processing is done, start destreaking.
+            my @chips;
+            push @chips, $it->{class_id};
+            $job_fault = check_states_magicDSRun($stage, $stage_id, \@chips, $rlabel, $need_magic, $it->{raw_magicked}, $it->{magic_ds_id}, $it->{dsRun_state});
+        }
     }
 
@@ -245,4 +248,8 @@
             # caller will fault the jobs
             return $error_code;
+        } elsif ($chip->{dsRun_state} eq 'failed_revert') {
+            # XXX: revert failures are rarely fixed. give up but say it's just not available not GONE 
+            print "magicDSRun.state = $dsRun_state for chipRun $stage_id is in state failed_revert cannot update\n";
+            return $PSTAMP_NOT_AVAILABLE;
         } elsif (($chip->{data_state} ne 'update') and ($chip->{data_state} ne 'full')) {
 
Index: /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_finish.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_finish.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_finish.pl	(revision 30676)
@@ -228,4 +228,6 @@
                 close JRL;
             } else {
+                my_die("No reglist for successful job: $job_id", $req_id, $PS_EXIT_PROG_ERROR) 
+                    if $fault eq $PSTAMP_SUCCESS;
                 print STDERR "no reglist file for job $job_id\n" if $verbose;
                 print $tdf "$rownum|$fault|$error_string|0|$job_id|";
Index: /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_get_image_job.pl
===================================================================
--- /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_get_image_job.pl	(revision 30675)
+++ /branches/eam_branches/ipp-20110213/pstamp/scripts/pstamp_get_image_job.pl	(revision 30676)
@@ -87,7 +87,4 @@
 }
 
-my $outdir = dirname($output_base);
-my $prefix = basename($output_base) . "_";
-my $results_file = $output_base . ".bundle_results";
 
 # Look for programs we need
@@ -99,13 +96,16 @@
 }
 
+my $outdir = dirname($output_base);
+my $basename = basename($path_base);
+my $outroot = $output_base ."_" . $basename;
+my $results_file = $output_base . ".bundle_results";
+
 {
     my $command = "$dist_bundle --camera $camera --stage $stage --stage_id $stage_id";
-    $command .= " --component $component";
-    $command .= " --path_base $path_base --outdir $outdir --results_file $results_file";
-    $command .= " --prefix $prefix";
+    $command .= " --results_file $results_file";
+    $command .= " --component $component --path_base $path_base --outroot $outroot";
+#    XXX: we need to do some work if we want to support muggle bundles
+#    $command .= " --no_magic if $no_magic";
     $command .= " --magicked" if $magicked;
-    # DANGER DANGER do not commit next line
-#    $command .= " --no_magic";
-    # DANGER DANGER do not commit last line
     $command .= " --dbname $dbname" if $dbname;
     $command .= " --verbose" if $verbose;
