Index: /trunk/ippScripts/scripts/summit_copy.pl
===================================================================
--- /trunk/ippScripts/scripts/summit_copy.pl	(revision 25370)
+++ /trunk/ippScripts/scripts/summit_copy.pl	(revision 25371)
@@ -12,4 +12,5 @@
 use Sys::Hostname;
 
+use Digest::MD5::File qw( file_md5_hex );
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
@@ -21,5 +22,5 @@
 
 # Parse the command-line arguments
-my ( $uri, $filename, $compress, $bytes, $md5, $nebulous, $exp_name, $inst, $telescope, $class, $class_id, $end_stage, $workdir,
+my ( $uri, $filename, $compress, $bytes, $md5, $nebulous, $exp_name, $inst, $telescope, $class, $class_id, 
      $dbname, $verbose, $no_update, $no_op, $timeout, $copies );
 GetOptions(
@@ -35,6 +36,4 @@
        'class=s'        => \$class,     # Class level
        'class_id=s'     => \$class_id,  # Class identifier
-       'end_stage=s'    => \$end_stage, # end of processing
-       'workdir=s'      => \$workdir,   # workdir
        'dbname=s'       => \$dbname,    # Database name
        'verbose'        => \$verbose,   # Print to stdout
@@ -62,8 +61,12 @@
 my $pztool = can_run('pztool')
     or (warn "Can't find pztool" and $missing_tools = 1);
+my $neblocate = can_run('neb-locate')
+    or (warn "Can't find neb-locate" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
     exit($PS_EXIT_CONFIG_ERROR);
 }
+
+my $ipprc = PS::IPP::Config->new();
 
 # dsget command
@@ -97,4 +100,11 @@
 }
 
+#
+# Find all instances of the new file and make sure they have the
+# same checksum and size.
+# if so pass the results to pztool to the results in pzDownloadImfile.
+# uncomment this to turn on
+# my ($new_bytes, $new_md5) = check_instances($filename, $nebulous, $compress);
+
 # command to update database
 $command  = "$pztool -copydone";
@@ -106,8 +116,10 @@
 $command .= " -class_id $class_id";
 $command .= " -uri $filename";
-# $command .= " -workdir $workdir";
 $command .= " -hostname $host";
-# $command .= " -end_stage $end_stage" if defined $end_stage;
 $command .= " -dbname $dbname" if defined $dbname;
+
+# XXX: TODO: see above. Don't do this until pztool and the DB have
+# been updated
+# $command .= " -md5sum $new_md5 -bytes $new_bytes";
 
 # update the database
@@ -122,4 +134,86 @@
 } else {
     print "skipping command: $command\n";
+}
+
+sub get_file_params
+{
+    my $filename = shift;
+
+    my $size = -s $filename;
+    my $md5 = file_md5_hex($filename);
+
+    return ($size, $md5);
+}
+
+sub check_instances {
+    my $filename = shift;
+    my $nebulous = shift;
+    my $compress = shift;
+
+    my @instances;
+    if ($nebulous) {
+        my $command = "$neblocate --path --all $filename";
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf )
+            = run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            my_die("Unable to perform neb-locate: $error_code",
+                $exp_name,
+                $inst,
+                $telescope,
+                $class,
+                $class_id,
+                $uri,
+                $error_code
+            );
+        }
+        @instances = split "\n", join "", @$stdout_buf;
+    } else {
+        if (!defined $ipprc) {
+            # we don't usually need this so defer instantaiating it
+            $ipprc = PS::IPP::Config->new();
+        }
+        my $resolved = $ipprc->file_resolve($filename);
+        if ($resolved) {
+            $instances[0] = $resolved;
+        }
+    }
+    if (! scalar @instances) {
+        my_die("no instances",
+                    $exp_name,
+                    $inst,
+                    $telescope,
+                    $class,
+                    $class_id,
+                    $uri,
+                    $PS_EXIT_UNKNOWN_ERROR
+            );
+    }
+
+    my ($new_bytes, $new_md5) = get_file_params($instances[0]);
+        
+    for (my $i = 1; $i < scalar @instances; $i++) {
+        my ($b, $m) = get_file_params($instances[$i]);
+        my $error = "";
+        if ($b ne $new_bytes) {
+            $error = "size of $instances[$i] does not match $instances[0]";
+        } elsif ($m != $new_md5) {
+            $error = "md5sum of $instances[$i] does not match $instances[0]";
+        }
+        if ($error) {
+            my_die($error,
+                    $exp_name,
+                    $inst,
+                    $telescope,
+                    $class,
+                    $class_id,
+                    $uri,
+                    $PS_EXIT_DATA_ERROR
+            );
+        }
+    }
+
+    return ($new_bytes, $new_md5);
+    
 }
 
