IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23895


Ignore:
Timestamp:
Apr 17, 2009, 9:02:27 AM (17 years ago)
Author:
Paul Price
Message:

Need to fix paths to point to new workdir.

File:
1 edited

Legend:

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

    r23894 r23895  
    1818use PS::IPP::Metadata::Config;
    1919use PS::IPP::Config 1.01 qw( :standard );
     20use File::Temp qw( tempfile );
    2021use Carp;
    2122
     
    3536
    3637# Parse the command-line arguments
    37 my ( $file_id, $source, $product, $fileset, $file, $workdir, $dbname, $verbose, $no_update );
     38my ( $file_id, $source, $product, $fileset, $file, $workdir, $dbname, $verbose, $no_update, $save_temps );
    3839
    3940GetOptions(
     
    4748           'verbose'           => \$verbose,   # Print to stdout
    4849           'no-update'         => \$no_update, # Don't update the database?
     50           'save-temps'        => \$save_temps, # Save temporary files?
    4951           ) or pod2usage( 2 );
    5052
     
    7779if ($file =~ m|^dbinfo\.\S+\.mdc$|) {
    7880    # Load into database
     81
     82    # Need to fix paths to point to new workdir
     83    my ($fixFile, $fixName) = tempfile( "$tempdir/$file.XXXX", UNLINK => !$save_temps ); # Fixed file
     84    open my $inFile, $filename or die "Can't open $filename\n"; # Input file
     85    my $workdir_old;            # Old workdir
     86    while (<$inFile>) {
     87        # XXX This is a global approach to fixing the path: it should fix anything and everything, but won't
     88        # work if there are multiple workdirs in a file and the bits are all mixed up.  To cover that case,
     89        # we should fix each of the elements (workdir, uri, path_base) separately.
     90        if (m|^\s*workdir\s+STR\s+(\S+)|) {
     91            $workdir_old = $1;
     92            $workdir_old =~ s|\@HOST\@|\\S+|;
     93        }
     94        if (defined $workdir_old) {
     95            s|$workdir_old|$workdir|;
     96        }
     97        print $fixFile $_;
     98    }
     99    close($inFile);
     100
    79101    my ($stage) = $file =~ m|^dbinfo\.(\S+)\.\d+\.mdc$|; # Stage of interest
    80102    my $tool = can_run("${stage}tool") or die "Can't find tool to load $file\n";
    81103
    82     my $command = "$tool -importrun -infile $filename"; # Command to execute
     104    my $command = "$tool -importrun -infile $fixName"; # Command to execute
    83105    $command .= " -dbname $dbname" if defined $dbname;
    84106    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    85107        run(command => $command, verbose => $verbose);
    86     die "Unable to load $filename\n" unless $success;
     108    die "Unable to load $fixName\n" unless $success;
    87109} elsif ($file =~ m|.*\.tgz$|) {
    88110    # Get contents of tarball
Note: See TracChangeset for help on using the changeset viewer.