IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 7, 2009, 11:19:33 AM (17 years ago)
Author:
bills
Message:

on errors set faults with new my_die subroutine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/receive_file.pl

    r24038 r24102  
    3636
    3737# Parse the command-line arguments
    38 my ( $file_id, $source, $product, $fileset, $fileset_id, $file, $workdir, $dbname, $verbose, $no_update, $save_temps );
     38my ( $file_id, $source, $product, $fileset, $fileset_id, $file, $component, $bytes, $md5sum, $workdir, $dbname, $verbose, $no_update, $save_temps );
    3939
    4040GetOptions(
     
    4545           'fileset_id=s'      => \$fileset_id, # database id for the fileset
    4646           'file=s'            => \$file, # File to retrieve
     47           'component=s'       => \$component, # component for this file (class_id, skycell_id or dbinfo)
     48           'bytes=i'           => \$bytes, # file size in bytes
     49           'md5sum=s'          => \$md5sum, # md5sum for file from data store
    4750           'workdir=s'         => \$workdir, # Working directory for output
    4851           'dbname=s'          => \$dbname,    # Database name
     
    6063    defined $fileset and
    6164    defined $file and
     65    defined $component and
     66    defined $bytes and
     67    defined $md5sum and
    6268    defined $workdir;
    6369
     
    7278    my $uri = "$source/$product/$fileset/$file"; # URI for datastore file
    7379    my $command = "dsget --uri $uri --filename $filename"; # Command to execute
     80    $command .= " --timeout 590";
     81    $command .= " --bytes $bytes --md5 $md5sum";
    7482
    7583    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    7684        run(command => $command, verbose => $verbose);
    77     die "Unable to retrieve file from $uri\n" unless $success;
     85    &my_die( "Unable to retrieve file from $uri\n", $file_id, $PS_EXIT_DATA_ERROR) unless $success;
    7886}
    7987my $mjd_copy = DateTime->now->mjd;   # MJD of finishing copy
     
    8795    my $fixFile;
    8896
    89     open $fixFile, ">$fixName" or die "can't open $fixName\n";
     97    open $fixFile, ">$fixName" or &my_die( "can't open $fixName\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
    9098
    9199    # Need to fix paths to point to new workdir
    92     open my $inFile, $filename or die "Can't open $filename\n"; # Input file
     100    open my $inFile, $filename or &my_die( "Can't open $filename\n", $file_id, $PS_EXIT_UNKNOWN_ERROR); # Input file
    93101    my $workdir_old;            # Old workdir
    94102    while (<$inFile>) {
     
    112120    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    113121        run(command => $command, verbose => $verbose);
    114     die "Unable to set dbinfo_uri for $fileset_id to  $fixName\n" unless $success;
     122    &my_die( "Unable to set dbinfo_uri for $fileset_id to  $fixName\n", $file_id, $PS_EXIT_UNKNOWN_ERROR) unless $success;
    115123#}
    116124
     
    122130        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    123131            run(command => $command, verbose => $verbose);
    124         die "Unable to get listing of tar file $filename\n" unless $success;
     132        &my_die( "Unable to get listing of tar file $filename\n", $file_id, $PS_EXIT_UNKNOWN_ERROR) unless $success;
    125133
    126134        my @lines = split(/\n/, join "", @$stdout_buf); # Lines from output
     
    140148        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    141149            run(command => $command, verbose => $verbose);
    142         die "Unable to extract tar file $filename\n" unless $success;
     150        &my_die( "Unable to extract tar file $filename\n", $file_id, $PS_EXIT_UNKNOWN_ERROR) unless $success;
    143151    }
    144152
     
    148156        my $target = "$workdir/$file"; # Target destination for file
    149157        my $to = $ipprc->file_create( $target ); # Target for move
    150         system("mv $from $to") == 0 or die "Unable to move $file into workdir $workdir: $!\n";
     158        system("mv $from $to") == 0 or &my_die( "Unable to move $file into workdir $workdir: $!\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
    151159    }
    152160} else {
    153     die "Unrecognised file: $file\n";
    154 }
    155 
    156 unlink $filename or die "Unable to unlink $filename\n";
     161    &my_die( "Unrecognised file: $file\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
     162}
     163
     164unlink $filename or &my_die( "Unable to unlink $filename\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
    157165my $mjd_extract = DateTime->now->mjd;   # MJD of finishing extract
    158166
Note: See TracChangeset for help on using the changeset viewer.