Index: trunk/pstamp/scripts/pstampparse.pl
===================================================================
--- trunk/pstamp/scripts/pstampparse.pl	(revision 28015)
+++ trunk/pstamp/scripts/pstampparse.pl	(revision 28021)
@@ -521,50 +521,5 @@
     my $dep_id;
 
-    # XXX: this code is repeated in queueGetImageJobs we should encapsulate it in a subroutine and share it
-    if ($stage ne 'raw') {
-        # updates for stack stage not supported yet
-        my $allow_wait_for_update = ($stage ne 'stack');
-        my $run_state = $image->{state};
-        my $data_state = $image->{data_state};
-        $data_state = $run_state if $stage eq 'stack';
-        if (($run_state =~ /purged/) or ($run_state =~ /scrubbed/)) {
-            # image is gone and it's not coming back
-            $newState = 'stop';
-            $fault = $PSTAMP_GONE;
-        } elsif (($run_state eq "error_cleaned") or ($data_state eq 'error_cleaned')) {
-            # if cleanup had an error don't get the user's hopes up
-            $newState = 'stop';
-            $fault = $PSTAMP_NOT_AVAILABLE;
-        } elsif (($data_state ne 'full') or ($need_magic and ($image->{magicked} < 0))) {
-            if ($stage eq 'chip') {
-                my $burntool_state = $image->{burntool_state};
-                # XXX: get value 13 from ppImage recipe 
-                if ($burntool_state and (abs($burntool_state) < 13)) {
-                    $newState = 'stop';
-                    $fault = $PSTAMP_NOT_AVAILABLE;
-                }
-            } 
-            if (!$allow_wait_for_update) {
-                print STDERR "wait for update not supported for stage $stage yet\n";
-                $newState = 'stop';
-                $fault = $PSTAMP_NOT_AVAILABLE;
-            }
-            if (!$fault) {
-                # wait for update unless the customer asks us not to
-                if (($option_mask & $PSTAMP_NO_WAIT_FOR_UPDATE)) {
-                    $newState = 'stop';
-                    $fault = $PSTAMP_NOT_AVAILABLE;
-                } elsif (!$image->{magicked}) {
-                    $newState = 'stop';
-                    $fault = $PSTAMP_NOT_DESTREAKED;
-                } else {
-                    # cause the image to be re-made
-                    # set up to queue an update run
-                    queue_update_run(\$newState, \$fault, \$dep_id, $image->{imagedb}, 
-                        $run_state, $stage, $image->{stage_id}, $image->{component}, $need_magic);
-                }
-            }
-        }
-    }
+    queueUpdatesIfNeeded($stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
 
     my $command = "$pstamptool -addjob  -req_id $req_id -job_type $row->{JOB_TYPE}"
@@ -706,31 +661,5 @@
         my $dep_id;
 
-        if ($stage ne 'raw') {
-            my $run_state = $image->{state};
-            my $data_state = $image->{data_state};
-            $data_state = $run_state if $stage eq "stack";
-#            if (($run_state eq 'goto_purged') or ($data_state eq 'purged') or
-#                ($run_state eq 'goto_scrubbed') or ($data_state eq 'scrubbed')) {
-            if (($run_state =~ /purged/) or ($run_state =~ /scrubbed/)) {
-                # image is gone and it's not coming back
-                $newState = 'stop';
-                $fault = $PSTAMP_GONE;
-            } elsif ($run_state eq "error_cleaned") {
-                # if cleanup had an error don't get the user's hopes up
-                $newState = 'stop';
-                $fault = $PSTAMP_NOT_AVAILABLE;
-            } elsif (($data_state ne 'full') or ($need_magic and ($image->{magicked} < 0))) {
-                # wait for update unless the customer asks us to not to
-                if ($option_mask & $PSTAMP_NO_WAIT_FOR_UPDATE) {
-                    $newState = 'stop';
-                    $fault = $PSTAMP_NOT_AVAILABLE;
-                } else {
-                    # cause the image to be re-made
-                    # set up to queue an update run
-                    queue_update_run(\$newState, \$fault, \$dep_id, $image->{imagedb}, 
-                        $run_state, $stage, $image->{stage_id}, $image->{component}, $need_magic);
-                }
-            }
-        }
+        queueUpdatesIfNeeded($stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
 
         $num_jobs++;
@@ -871,15 +800,16 @@
 }
 
-sub queue_update_run 
+sub get_dependent 
 {
     my ($r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $component, $need_magic) = @_;
 
-    # XXX: The update process for warp and subsequent stages requires 
-    # destreaking to run because the -pending queries require it when magicked > 0
-    # queries. 
-    # The case of stack-stack diffs is taken care of in pstamp_checkdependent
+    # XXX: The update process for warp and subsequent stages requires # destreaking to be performed
+    # because the -pending queries require the inputs to have magicked >= 0
+    # The case of stack-stack diffs not needing to be destreaked is taken care of in pstamp_checkdependent
     $need_magic = 1 if $imagedb eq 'gpc1';
 
-    if (($state ne 'cleaned') and ($state ne 'update') and ($state ne 'goto_cleaned')) {
+    # chipRun's can be in full state if destreaking is necessary
+    if (($state ne 'cleaned') and ($state ne 'update') and ($state ne 'goto_cleaned') and 
+        ($stage eq 'chip' and $state eq 'full')) {
         my_die("$stage $stage_id is in unexpected state $state", $PS_EXIT_PROG_ERROR);
     }
@@ -917,4 +847,50 @@
 }
 
+sub queueUpdatesIfNeeded {
+    my $stage = shift;
+    my $image = shift;
+    my $option_mask = shift;
+    my $r_newState = shift;
+    my $r_fault = shift;
+    my $r_dep_id = shift;
+
+    if ($stage ne 'raw') {
+        my $run_state = $image->{state};
+        my $data_state = $image->{data_state};
+        $data_state = $run_state if $stage eq 'stack';
+        if (($run_state =~ /purged/) or ($run_state =~ /scrubbed/) or ($run_state eq 'drop')) {
+            # image is gone and it's not coming back
+            $$r_newState = 'stop';
+            $$r_fault = $PSTAMP_GONE;
+        } elsif (($run_state eq "error_cleaned") or ($data_state eq 'error_cleaned')) {
+            # if cleanup had an error don't get the user's hopes up set fault to gone
+            $$r_newState = 'stop';
+            $$r_fault = $PSTAMP_GONE;
+        } elsif (($data_state ne 'full') or ($need_magic and ($image->{magicked} < 0))) {
+   
+            if ($stage eq 'stack') {
+                print STDERR "Stamps cannot be made from cleaned stacks.\n";
+                $$r_newState = 'stop';
+                $$r_fault = $PSTAMP_GONE;
+            }
+            if (!$$r_fault) {
+                # wait for update unless the customer asks us not to
+                if (($option_mask & $PSTAMP_NO_WAIT_FOR_UPDATE)) {
+                    $$r_newState = 'stop';
+                    $$r_fault = $PSTAMP_NOT_AVAILABLE;
+                } elsif (!$image->{magicked}) {
+                    $$r_newState = 'stop';
+                    $$r_fault = $PSTAMP_NOT_DESTREAKED;
+                } else {
+                    # cause the image to be re-made
+                    # set up to queue an update run
+                    get_dependent(\$$r_newState, \$$r_fault, $r_dep_id, $image->{imagedb}, 
+                        $run_state, $stage, $image->{stage_id}, $image->{component}, $need_magic);
+                }
+            }
+        }
+    }
+}
+
 sub write_params {
     my $output_base = shift;
