Index: trunk/ippScripts/scripts/dist_component.pl
===================================================================
--- trunk/ippScripts/scripts/dist_component.pl	(revision 23743)
+++ trunk/ippScripts/scripts/dist_component.pl	(revision 23777)
@@ -58,5 +58,5 @@
 # Parse the command-line arguments
 my ($dist_id, $camera, $stage, $stage_id, $component, $path_base, $chip_path_base, $clean);
-my ($outroot, $run_state, $data_state, $magicked, $no_magic, $poor_quality);
+my ($outdir, $run_state, $data_state, $magicked, $no_magic, $poor_quality);
 my ($dbname, $save_temps, $verbose, $no_update, $logfile);
 
@@ -71,8 +71,8 @@
            'state=s'        => \$run_state,  # state of the run
            'data_state=s'   => \$data_state, # data_state for this component
-           'poor_quality'      => \$poor_quality,  # the processing for this component did not produced images
+           'poor_quality'   => \$poor_quality,  # the processing for this component did not produced images
            'no_magic'       => \$no_magic,   # magic is not required for this distribution run
            'magicked'       => \$magicked,   # magicked state for this component
-           'outroot=s'      => \$outroot,    # "directory" for outputs
+           'outdir=s'       => \$outdir,     # "directory" for outputs
            'clean'          => \$clean,      # create clean distribution
            'save-temps'     => \$save_temps, # Save temporary files?
@@ -84,5 +84,5 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --dist_id --camera --stage --stage_id --component --path_base --outroot",
+pod2usage( -msg => "Required options: --dist_id --camera --stage --stage_id --component --path_base --outdir",
            -exitval => 3) unless
     defined $dist_id and
@@ -92,9 +92,9 @@
     defined $component and
     defined $path_base and
-    defined $outroot;
+    defined $outdir;
 
 $ipprc->redirect_output($logfile) if $logfile;
 
-if (($stage eq 'raw') and !defined $chip_path_base) {
+if (($stage eq 'raw') and !$clean and !defined $chip_path_base) {
     pod2usage( -msg => "Required options: --chip_path_base for raw stage", -exitval => 3);
 }
@@ -105,14 +105,10 @@
 
 # making a clean bundle of raw images doesn't make sense
-if (($stage eq "raw") and $clean) {
-    # well I suppose we could ship the registration log file. naw.
-    &my_die("cannot create clean run at raw stage", $dist_id, $component, $PS_EXIT_CONFIG_ERROR);
-}
 
 # create the output directories if it is not a nebulous path and it doesn't exist
-if (index($outroot, "neb://") != 0) {
-    if (! -e $outroot ) {
-        my $code = system "mkdir -p $outroot";
-        &my_die("cannot create output directory $outroot", $dist_id, $component,
+if (index($outdir, "neb://") != 0) {
+    if (! -e $outdir ) {
+        my $code = system "mkdir -p $outdir";
+        &my_die("cannot create output directory $outdir", $dist_id, $component,
                 $code >> 8) if $code;
     }
@@ -122,7 +118,7 @@
 # note: We my_die in get_file_list if something goes wrong. 
 
-my $file_list = get_file_list($stage, $component, $path_base);
-
-if ($stage ne 'fake') {
+my $file_list = get_file_list($stage, $component, $path_base, $clean);
+
+if (($stage ne 'raw') and ($stage ne 'fake')) {
     # If the file list is empty it is an error because we should at least get a config dump file
     # except for fake stage which doesn't do anything yet
@@ -132,5 +128,5 @@
 # set up directory for temporary files
 
-my $tmpdir  = "$outroot/tmpdir.$dist_id.$component";
+my $tmpdir  = "$outdir/tmpdir.$dist_id.$component";
 if (-e $tmpdir) {
     if (-d $tmpdir) {
@@ -155,4 +151,5 @@
 
 # foreach my $file_rule (keys %$file_list) {
+my $num_files = 0;
 foreach my $file (@$file_list) {
     # check whether this file rule refers to an image, mask, or variance fits image
@@ -188,4 +185,5 @@
     # we need to pre-process the image before adding to the bundle. Save the path names.
     # the images will be created below
+    $num_files++;
     if ($image_type && $nan_masked_pixels) {
         # save the 
@@ -251,5 +249,6 @@
 my $bytes;
 my $md5sum;
-if ($stage eq 'fake') {
+if (0) {
+if (($stage eq 'fake')  or (($stage eq 'raw') and $clean)) {
     open DUMMY, ">$tmpdir/fake.$component" or &my_die("Unable to create placeholder for fake component",
         $dist_id, $component, $PS_EXIT_CONFIG_ERROR);
@@ -257,11 +256,12 @@
     close DUMMY;
 }
-# create the tarfile
-{
+}
+if ($num_files) {
+    # create the tarfile
     # XXX TODO: create a file rule for the tar file name
     my $tbase = basename($path_base);
     $tbase .= ".$component" if $component;
     $file_name = "$tbase.tgz";
-    my $tarfile = "$outroot/$file_name";
+    my $tarfile = "$outdir/$file_name";
 
     my $command = "tar -C $tmpdir --owner=ipp --group=users -czhf $tarfile .";
@@ -279,9 +279,12 @@
     &my_die("unable to compute md5sum for $tarfile", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR) if !$md5sum;
 
-    my @finfo = stat($tarfile);
-    &my_die("unable to stat $tarfile", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR) if !@finfo;
-    $bytes = $finfo[7];
+    $bytes = -s $tarfile;
 
     delete_tmpdir($tmpdir);
+} else {
+    # no files for this component
+    $file_name = "none";
+    $bytes = 0;
+    $md5sum = "0";
 }
 {
@@ -360,4 +363,5 @@
     my $component = shift;
     my $path_base = shift;
+    my $clean = shift;
 
     my @file_list;
@@ -366,8 +370,10 @@
         # eventually rawImfile will have a path_base that we'll need to add '.fits'
         # XXX do we want to distribute the registration log files?
-        my %file;
-        $file{file_rule} = "RAW.IMAGE";
-        $file{name} = $path_base;
-        push @file_list, \%file;
+        if (!$clean) {
+            my %file;
+            $file{file_rule} = "RAW.IMAGE";
+            $file{name} = $path_base;
+            push @file_list, \%file;
+        }
         return \@file_list;
     }
