Index: trunk/ippScripts/scripts/receive_file.pl
===================================================================
--- trunk/ippScripts/scripts/receive_file.pl	(revision 23894)
+++ trunk/ippScripts/scripts/receive_file.pl	(revision 23895)
@@ -18,4 +18,5 @@
 use PS::IPP::Metadata::Config;
 use PS::IPP::Config 1.01 qw( :standard );
+use File::Temp qw( tempfile );
 use Carp;
 
@@ -35,5 +36,5 @@
 
 # Parse the command-line arguments
-my ( $file_id, $source, $product, $fileset, $file, $workdir, $dbname, $verbose, $no_update );
+my ( $file_id, $source, $product, $fileset, $file, $workdir, $dbname, $verbose, $no_update, $save_temps );
 
 GetOptions(
@@ -47,4 +48,5 @@
            'verbose'           => \$verbose,   # Print to stdout
            'no-update'         => \$no_update, # Don't update the database?
+           'save-temps'        => \$save_temps, # Save temporary files?
            ) or pod2usage( 2 );
 
@@ -77,12 +79,32 @@
 if ($file =~ m|^dbinfo\.\S+\.mdc$|) {
     # Load into database
+
+    # Need to fix paths to point to new workdir
+    my ($fixFile, $fixName) = tempfile( "$tempdir/$file.XXXX", UNLINK => !$save_temps ); # Fixed file
+    open my $inFile, $filename or die "Can't open $filename\n"; # Input file
+    my $workdir_old;            # Old workdir
+    while (<$inFile>) {
+        # XXX This is a global approach to fixing the path: it should fix anything and everything, but won't
+        # work if there are multiple workdirs in a file and the bits are all mixed up.  To cover that case,
+        # we should fix each of the elements (workdir, uri, path_base) separately.
+        if (m|^\s*workdir\s+STR\s+(\S+)|) {
+            $workdir_old = $1;
+            $workdir_old =~ s|\@HOST\@|\\S+|;
+        }
+        if (defined $workdir_old) {
+            s|$workdir_old|$workdir|;
+        }
+        print $fixFile $_;
+    }
+    close($inFile);
+
     my ($stage) = $file =~ m|^dbinfo\.(\S+)\.\d+\.mdc$|; # Stage of interest
     my $tool = can_run("${stage}tool") or die "Can't find tool to load $file\n";
 
-    my $command = "$tool -importrun -infile $filename"; # Command to execute
+    my $command = "$tool -importrun -infile $fixName"; # Command to execute
     $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
-    die "Unable to load $filename\n" unless $success;
+    die "Unable to load $fixName\n" unless $success;
 } elsif ($file =~ m|.*\.tgz$|) {
     # Get contents of tarball
