Index: /trunk/ippScripts/scripts/dist_bundle.pl
===================================================================
--- /trunk/ippScripts/scripts/dist_bundle.pl	(revision 30652)
+++ /trunk/ippScripts/scripts/dist_bundle.pl	(revision 30653)
@@ -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: /trunk/ippTools/share/disttool_pending_raw.sql
===================================================================
--- /trunk/ippTools/share/disttool_pending_raw.sql	(revision 30652)
+++ /trunk/ippTools/share/disttool_pending_raw.sql	(revision 30653)
@@ -12,5 +12,6 @@
     TRIM(TRAILING '.fits' FROM rawImfile.uri) AS path_base,
     CAST(NULL AS CHAR(255)) AS alt_path_base,
-    chipProcessedImfile.path_base as chip_path_base,
+    -- pass camera stage path base since we want the camera mask file. The script knows what to do
+    camProcessedExp.path_base as chip_path_base,
     CAST(NULL AS CHAR(255)) AS state,
     CAST(NULL AS CHAR(255)) AS data_state,
@@ -26,4 +27,6 @@
 JOIN chipProcessedImfile
     USING(chip_id, class_id)
+JOIN camRun USING(chip_id)
+JOIN camProcessedExp using(cam_id)
 LEFT JOIN distComponent 
     ON distRun.dist_id = distComponent.dist_id 
@@ -36,4 +39,7 @@
     AND distComponent.dist_id IS NULL
     AND (rawExp.magicked OR distRun.no_magic)
+    -- need to have magicked the chip image which makes the camera mask
+    AND chipProcessedImfile.magicked != 0
+    AND camRun.magicked > 0 
     AND (Label.active OR Label.active IS NULL)
 UNION
@@ -52,5 +58,6 @@
     TRIM(TRAILING '.fits' FROM rawImfile.uri) AS path_base,
     magicDSFile.backup_path_base AS alt_path_base,
-    chipProcessedImfile.path_base AS chip_path_base,
+    -- pass camera stage path base since we want the camera mask file. The script knows what to do
+    camProcessedExp.path_base AS chip_path_base,
     CAST('full' AS CHAR(255)) AS state,
     CAST('full' AS CHAR(255)) AS data_state,
@@ -77,6 +84,6 @@
     AND distRun.clean = 0
     AND distComponent.dist_id IS NULL
-    AND chipProcessedImfile.data_state = 'full'
-    AND chipProcessedImfile.magicked > 0
+    AND chipProcessedImfile.magicked != 0
+    AND camRun.magicked > 0 
     AND (Label.active OR Label.active IS NULL)
 UNION
