Index: /trunk/dbconfig/changes.txt
===================================================================
--- /trunk/dbconfig/changes.txt	(revision 24037)
+++ /trunk/dbconfig/changes.txt	(revision 24038)
@@ -1088,2 +1088,10 @@
 -- This key makes it faster to find the ccd_temp for XY24
 ALTER TABLE rawImfile ADD KEY(dateobs);
+
+ALTER TABLE receiveSource ADD COLUMN status_product VARCHAR(64);
+ALTER TABLE receiveSource ADD COLUMN ds_dbname VARCHAR(64);
+ALTER TABLE receiveSource ADD COLUMN ds_dbhost VARCHAR(64);
+
+ALTER TABLE receiveFileset ADD COLUMN state VARCHAR(64);
+ALTER TABLE receiveFileset ADD COLUMN dbinfo_uri VARCHAR(255);
+ALTER TABLE receiveFileset ADD COLUMN fault SMALLINT NOT NULL DEFAULT 0;
Index: /trunk/dbconfig/receive.md
===================================================================
--- /trunk/dbconfig/receive.md	(revision 24037)
+++ /trunk/dbconfig/receive.md	(revision 24038)
@@ -8,4 +8,7 @@
 	comment		STR	255	# Key
 	fileset_last	STR	128
+        status_product  STR     64
+        ds_dbname       STR     64
+        ds_dbhost       STR     64
 END
 
@@ -14,4 +17,7 @@
 	source_id	S64	0	# Key fkey (source_id) ref receiveSource(source_id)
 	fileset		STR	128
+        state           STR     64
+        dbinfo_uri      STR     255
+	fault		S32	0	# Key
 END
 
Index: /trunk/ippScripts/Build.PL
===================================================================
--- /trunk/ippScripts/Build.PL	(revision 24037)
+++ /trunk/ippScripts/Build.PL	(revision 24038)
@@ -87,4 +87,6 @@
         scripts/receive_fileset.pl
         scripts/receive_file.pl
+        scripts/receive_advance.pl
+        scripts/receive_setstatus.pl
         scripts/rcserver_checkstatus.pl
     )],
Index: /trunk/ippScripts/scripts/dist_queue_runs.pl
===================================================================
--- /trunk/ippScripts/scripts/dist_queue_runs.pl	(revision 24037)
+++ /trunk/ippScripts/scripts/dist_queue_runs.pl	(revision 24038)
@@ -98,4 +98,18 @@
 }
 
+# queue rcRuns for any distRuns that have completed and have interested destinations
+{
+    my $command = "$disttool -queuercrun";
+    $command .= " -dbname $dbname" if defined $dbname;
+    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 $command error_code: $error_code", $error_code);
+    }
+    # display the output from the command
+    print STDERR join "", @$stdout_buf if $verbose;
+}
+
 exit 0;
 
Index: /trunk/ippScripts/scripts/receive_advance.pl
===================================================================
--- /trunk/ippScripts/scripts/receive_advance.pl	(revision 24038)
+++ /trunk/ippScripts/scripts/receive_advance.pl	(revision 24038)
@@ -0,0 +1,137 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+## report the program and machine
+use Sys::Hostname;
+my $host = hostname();
+print "Starting script $0 on $host\n\n";
+
+use DateTime;
+my $mjd_start = DateTime->now->mjd;   # MJD of starting script
+
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+use IPC::Cmd 0.36 qw( can_run run );
+use PS::IPP::Metadata::Config;
+use PS::IPP::Config 1.01 qw( :standard );
+use File::Temp qw( tempfile );
+use File::Basename qw( basename );
+use Carp;
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $receivetool = can_run('receivetool') or (warn "Can't find receivetool" and $missing_tools = 1);
+my $receive_setstatus = can_run('receive_setstatus.pl') or (warn "Can't find receive_setstatus.pl" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
+# Parse the command-line arguments
+my ( $fileset_id, $fileset, $dbinfo_uri, $product, $ds_dbname, $ds_dbhost, $dbname, $verbose, $no_update, $save_temps );
+
+GetOptions(
+           'fileset_id=s'      => \$fileset_id,# database id for the fileset
+           'fileset=s'         => \$fileset,   # fileset name
+           'dbinfo_uri=s'      => \$dbinfo_uri,# uri for the database info file
+           'status_product=s'  => \$product,   # Product for status update
+           'ds_dbname=s'       => \$ds_dbname, # data store host
+           'ds_dbhost=s'       => \$ds_dbhost, # data store dbname
+           'dbname=s'          => \$dbname,    # Database name
+           'verbose'           => \$verbose,   # Print to stdout
+           'no-update'         => \$no_update, # Don't update the database?
+           'save-temps'        => \$save_temps, # Save temporary files?
+           ) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage( -msg => "Required options: --file_id --source --product --fileset --file --workdir",
+           -exitval => $PS_EXIT_CONFIG_ERROR) unless
+    defined $fileset_id;
+
+my $ipprc = PS::IPP::Config->new() or
+    &my_die( "Unable to set up", $fileset_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
+
+# update the fileset entry
+
+if ($dbinfo_uri and ($dbinfo_uri ne "NULL")) {
+    my $filename = basename($dbinfo_uri);
+    my ($stage) = $filename =~ m|^dbinfo\.(\S+)\.\d+\.mdc$|; # Stage of interest
+    my $tool_name;
+    if ($stage eq "raw") {
+        $tool_name = "regtool";
+    } else {
+        $tool_name = "${stage}tool";
+    }
+    my $tool = can_run("$tool_name") or &my_die("Can't find tool to load $dbinfo_uri\n", $fileset_id, $PS_EXIT_CONFIG_ERROR);
+
+    my $file = $ipprc->file_resolve($dbinfo_uri);
+    &my_die("Unable to resolve $dbinfo_uri\n", $PS_EXIT_UNKNOWN_ERROR) unless $file;
+
+    my $command = "$tool -importrun -infile $file"; # Command to execute
+    $command .= " -dbname $dbname" if defined $dbname;
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    &my_die("Unable to load $file\n", $fileset_id, $PS_EXIT_UNKNOWN_ERROR) unless $success;
+
+    # XXX: once the dbinfo file is imported we cannot revert this fileset
+}
+
+if ($product) {
+    my $command = "$receive_setstatus --dbname $ds_dbname --status_product $product";
+    $command .= " --received_fs_name $fileset --fault 0";
+    if ($ds_dbname) {
+        $command .= " --dbname $ds_dbname";
+    } else {
+        # XXX: is falling back to the other database a good idea?
+        $command .= " --dbname $dbname" if defined $dbname;
+    }
+
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    &my_die("Unable to set transfer status on data store for $fileset_id\n", $fileset_id, $PS_EXIT_UNKNOWN_ERROR) unless $success;
+}
+
+# All done
+{
+    my $command = "$receivetool -updatefileset -fileset_id $fileset_id -set_state full";
+    $command .= " -dbname $dbname" if defined $dbname;
+
+    unless (defined $no_update) {
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        &my_die("Unable to add result for $fileset_id\n", $fileset_id, $PS_EXIT_CONFIG_ERROR) unless $success;
+    }
+}
+
+# Pau.
+
+
+sub my_die
+{
+    my $msg = shift;            # Exit message
+    my $fileset_id = shift;     # Fileset identifier
+    my $fault = shift;          # Fault code
+
+    $fault = $PS_EXIT_PROG_ERROR unless defined $fault;
+
+    carp($msg);
+    if (defined $fileset_id and not $no_update) {
+        my $command = "$receivetool -updatefileset";
+        $command .= " -fileset_id $fileset_id";
+        $command .= " -fault $fault";
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+    }
+    exit $fault;
+}
+
+
+__END__
Index: /trunk/ippScripts/scripts/receive_file.pl
===================================================================
--- /trunk/ippScripts/scripts/receive_file.pl	(revision 24037)
+++ /trunk/ippScripts/scripts/receive_file.pl	(revision 24038)
@@ -36,5 +36,5 @@
 
 # Parse the command-line arguments
-my ( $file_id, $source, $product, $fileset, $file, $workdir, $dbname, $verbose, $no_update, $save_temps );
+my ( $file_id, $source, $product, $fileset, $fileset_id, $file, $workdir, $dbname, $verbose, $no_update, $save_temps );
 
 GetOptions(
@@ -43,4 +43,5 @@
            'product=s'         => \$product, # Product for data
            'fileset=s'         => \$fileset, # Fileset for data
+           'fileset_id=s'      => \$fileset_id, # database id for the fileset
            'file=s'            => \$file, # File to retrieve
            'workdir=s'         => \$workdir, # Working directory for output
@@ -61,4 +62,6 @@
     defined $workdir;
 
+$tempdir .= "/$file_id";
+
 my $ipprc = PS::IPP::Config->new() or
     &my_die( "Unable to set up", $file_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
@@ -80,6 +83,11 @@
     # Load into database
 
+    my $target = "$workdir/$file"; # Target destination for file
+    my $fixName = $ipprc->file_create( $target ); # Target for move
+    my $fixFile;
+
+    open $fixFile, ">$fixName" or die "can't open $fixName\n";
+
     # 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
@@ -98,13 +106,13 @@
     }
     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 $fixName"; # Command to execute
+    close($fixFile);
+#{
+    my $command = "$receivetool -updatefileset -fileset_id $fileset_id -dbinfo_uri $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 $fixName\n" unless $success;
+    die "Unable to set dbinfo_uri for $fileset_id to  $fixName\n" unless $success;
+#}
+
 } elsif ($file =~ m|.*\.tgz$|) {
     # Get contents of tarball
Index: /trunk/ippScripts/scripts/receive_setstatus.pl
===================================================================
--- /trunk/ippScripts/scripts/receive_setstatus.pl	(revision 24037)
+++ /trunk/ippScripts/scripts/receive_setstatus.pl	(revision 24038)
@@ -51,10 +51,13 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --dest_id --status_uri",
+pod2usage( -msg => "Required options: --status_fs_name --status_product",
            -exitval => 3) unless
-    defined $status_fs_name and
+    defined $received_fs_name and
     defined $status_product and
     defined $fault;
 #    and ($fault == 0 or defined $status_file);
+
+# if a name for the status fileset is not provided use the received value
+$status_fs_name = $received_fs_name if !defined $status_fs_name;
 
 $ipprc->redirect_output($logfile) if $logfile;
Index: /trunk/ippTasks/dist.pro
===================================================================
--- /trunk/ippTasks/dist.pro	(revision 24037)
+++ /trunk/ippTasks/dist.pro	(revision 24038)
@@ -42,4 +42,7 @@
     active true
   end
+  task dist.queueruns
+    active true
+  end
 end
 macro dist.off
@@ -54,4 +57,7 @@
   end
   task dist.advance.run
+    active false
+  end
+  task dist.queueruns
     active false
   end
@@ -298,5 +304,5 @@
 
   periods      -poll $RUNPOLL
-  periods      -exec 10
+  periods      -exec 30
   periods      -timeout 45
   npending     1
Index: /trunk/ippTasks/rcserver.pro
===================================================================
--- /trunk/ippTasks/rcserver.pro	(revision 24037)
+++ /trunk/ippTasks/rcserver.pro	(revision 24038)
@@ -173,5 +173,6 @@
 
   periods      -poll $LOADPOLL
-  periods      -exec $LOADEXEC
+#  periods      -exec $LOADEXEC
+  periods      -exec 20
   periods      -timeout 30
   npending     1
Index: /trunk/ippTasks/receive.pro
===================================================================
--- /trunk/ippTasks/receive.pro	(revision 24037)
+++ /trunk/ippTasks/receive.pro	(revision 24038)
@@ -20,4 +20,7 @@
 ### 
 ### receivetool -revert: remove result after something goes wrong
+###
+### receivetool -toadvance: filesets for which all files have been downloaded and are ready
+### to complete processing
 
 # test for required global variables
@@ -27,4 +30,5 @@
 book init receiveFileset
 book init receiveFile
+book init receiveAdvance
 
 macro receive.status
@@ -32,4 +36,5 @@
   book listbook receiveFileset
   book listbook receiveFile
+  book listbook receiveAdvance
 end
 
@@ -38,4 +43,5 @@
   book init receiveFileset
   book init receiveFile
+  book init receiveAdvance
 end
 
@@ -59,4 +65,10 @@
     active true
   end
+  task receive.advance.load
+    active true
+  end
+  task receive.advance.run
+    active true
+  end
 end
 
@@ -80,4 +92,10 @@
     active false
   end
+  task receive.advance.load
+    active false
+  end
+  task receive.advance.run
+    active false
+  end
 end
 
@@ -85,4 +103,5 @@
 # this variable will cycle through the known database names
 $receive_DB = 0
+$receive_Advance_DB = 0
 
 task	       receive.source.load
@@ -380,4 +399,5 @@
     book getword receiveFile $pageName product -var PRODUCT
     book getword receiveFile $pageName fileset -var FILESET
+    book getword receiveFile $pageName fileset_id -var FILESET_ID
     book getword receiveFile $pageName file -var FILE
     book getword receiveFile $pageName workdir -var WORKDIR
@@ -388,5 +408,5 @@
     stderr $LOGDIR/receive.file.log
 
-    $run = receive_file.pl --file_id $FILE_ID --source $SOURCE --product $PRODUCT --fileset $FILESET --file $FILE --workdir $WORKDIR
+    $run = receive_file.pl --file_id $FILE_ID --source $SOURCE --product $PRODUCT --fileset $FILESET --fileset_id $FILESET_ID --file $FILE --workdir $WORKDIR
     add_standard_args run
 
@@ -419,2 +439,112 @@
   end
 end
+
+task	       receive.advance.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/receive.advance.log
+
+  task.exec
+    $run = receivetool -toadvance
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$receive_Advance_DB
+      $run = $run -dbname $DB:$receive_Advance_DB
+      $receive_Advance_DB ++
+      if ($receive_Advance_DB >= $DB:n) set receive_Advance_DB = 0
+    end
+    add_poll_args run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout receiveAdvance -key fileset_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook receiveAdvance
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup receiveAdvance
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task	       receive.advance.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 60
+
+  task.exec
+    book npages receiveAdvance -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    book getpage receiveAdvance 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword receiveAdvance $pageName pantaskState RUN
+    book getword receiveAdvance $pageName fileset_id -var FILESET_ID
+    book getword receiveAdvance $pageName fileset -var FILESET
+    book getword receiveAdvance $pageName dbinfo_uri -var DBINFO_URI
+    book getword receiveAdvance $pageName status_product -var STATUS_PRODUCT
+    book getword receiveAdvance $pageName ds_dbname -var DS_DBNAME
+    book getword receiveAdvance $pageName ds_dbhost -var DS_DBHOST
+    book getword receiveAdvance $pageName dbname -var DBNAME
+
+    stdout $LOGDIR/receive.advance.log
+    stderr $LOGDIR/receive.advance.log
+
+    $run = receive_advance.pl --fileset_id $FILESET_ID --fileset $FILESET --dbinfo_uri $DBINFO_URI --status_product $STATUS_PRODUCT --ds_dbname $DS_DBNAME --ds_dbhost $DS_DBHOST
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit receiveAdvance $options:0 $JOB_STATUS
+  end
+
+  # locked list
+  task.exit    crash
+    showcommand crash
+    echo "hostname: $JOB_HOSTNAME"
+    book setword receiveAdvance $options:0 pantaskState CRASH
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword receiveAdvance $options:0 pantaskState TIMEOUT
+  end
+end
Index: /trunk/ippTools/share/Makefile.am
===================================================================
--- /trunk/ippTools/share/Makefile.am	(revision 24037)
+++ /trunk/ippTools/share/Makefile.am	(revision 24038)
@@ -179,4 +179,5 @@
      receivetool_pendingfile.sql \
      receivetool_revert.sql \
+     receivetool_toadvance.sql \
      regtool_create_dup_table.sql \
      regtool_export_exp.sql \
Index: /trunk/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- /trunk/ippTools/share/pxadmin_create_tables.sql	(revision 24037)
+++ /trunk/ippTools/share/pxadmin_create_tables.sql	(revision 24038)
@@ -1315,4 +1315,7 @@
     comment VARCHAR(255),       -- for human memory
     fileset_last VARCHAR(128),  -- last fileset seen
+    status_product VARCHAR(64), -- status data store product
+    ds_dbname VARCHAR(64),      -- status data store's database name
+    ds_dbhost VARCHAR(64),      -- status data store's host name
     PRIMARY KEY(source_id),
     KEY(source),
@@ -1326,4 +1329,7 @@
     source_id BIGINT NOT NULL,  -- link to receiveSource
     fileset VARCHAR(128) NOT NULL, -- fileset to receive
+    state VARCHAR(64), -- new or full
+    dbinfo_uri VARCHAR(255), -- uri for database dump for this fileset's run
+    fault SMALLINT NOT NULL DEFAULT 0, -- Fault code
     PRIMARY KEY(fileset_id),
     KEY(source_id),
Index: /trunk/ippTools/share/receivetool_pendingfile.sql
===================================================================
--- /trunk/ippTools/share/receivetool_pendingfile.sql	(revision 24037)
+++ /trunk/ippTools/share/receivetool_pendingfile.sql	(revision 24038)
@@ -5,4 +5,5 @@
     workdir,
     fileset,
+    fileset_id,
     file
 FROM receiveFile
Index: /trunk/ippTools/share/receivetool_toadvance.sql
===================================================================
--- /trunk/ippTools/share/receivetool_toadvance.sql	(revision 24038)
+++ /trunk/ippTools/share/receivetool_toadvance.sql	(revision 24038)
@@ -0,0 +1,15 @@
+SELECT
+    receiveFileset.fileset_id,
+    receiveFileset.fileset,
+    receiveFileset.dbinfo_uri,
+    receiveSource.status_product,
+    receiveSource.ds_dbname,
+    receiveSource.ds_dbhost
+FROM receiveFileset 
+    JOIN receiveSource USING(source_id)
+    JOIN receiveFile USING(fileset_id)
+    JOIN receiveResult USING(file_id)
+WHERE receiveFileset.state = 'new' 
+    AND receiveFileset.fault = 0
+GROUP BY fileset_id 
+HAVING COUNT(receiveFile.file_id) = COUNT(receiveResult.file_id) 
Index: /trunk/ippTools/src/Makefile.am
===================================================================
--- /trunk/ippTools/src/Makefile.am	(revision 24037)
+++ /trunk/ippTools/src/Makefile.am	(revision 24038)
@@ -19,7 +19,6 @@
 	regtool \
 	stacktool \
-	warptool
-
-#	receivetool
+	warptool \
+	receivetool
 
 
Index: /trunk/ippTools/src/receivetool.c
===================================================================
--- /trunk/ippTools/src/receivetool.c	(revision 24037)
+++ /trunk/ippTools/src/receivetool.c	(revision 24038)
@@ -1,4 +1,4 @@
 /*
- * disttool.c
+ * receivetool.c
  *
  * Copyright (C) 2008
@@ -36,7 +36,9 @@
 static bool updatelastMode(pxConfig *config);
 static bool pendingfilesetMode(pxConfig *config);
+static bool updatefilesetMode(pxConfig *config);
 static bool addfileMode(pxConfig *config);
 static bool pendingfileMode(pxConfig *config);
 static bool addresultMode(pxConfig *config);
+static bool toadvanceMode(pxConfig *config);
 static bool revertMode(pxConfig *config);
 
@@ -65,4 +67,6 @@
         MODECASE(RECEIVETOOL_MODE_UPDATELAST, updatelastMode);
         MODECASE(RECEIVETOOL_MODE_PENDINGFILESET, pendingfilesetMode);
+        MODECASE(RECEIVETOOL_MODE_UPDATEFILESET, updatefilesetMode);
+        MODECASE(RECEIVETOOL_MODE_TOADVANCE, toadvanceMode);
         MODECASE(RECEIVETOOL_MODE_ADDFILE, addfileMode);
         MODECASE(RECEIVETOOL_MODE_PENDINGFILE, pendingfileMode);
@@ -102,6 +106,9 @@
     PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
     PXOPT_LOOKUP_STR(last, config->args, "-last",  false, false);
-
-    if (!receiveSourceInsert(config->dbh, 0, source, product, workdir, comment, last)) {
+    PXOPT_LOOKUP_STR(status_product, config->args, "-status_product",  false, false);
+    PXOPT_LOOKUP_STR(ds_dbname, config->args, "-ds_dbname",  false, false);
+    PXOPT_LOOKUP_STR(ds_dbhost, config->args, "-ds_dbhost",  false, false);
+
+    if (!receiveSourceInsert(config->dbh, 0, source, product, workdir, comment, last, status_product, ds_dbname, ds_dbhost)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
         return false;
@@ -231,5 +238,5 @@
         psFree(output);
 
-        if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset)) {
+        if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset, "new", NULL, 0)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
             psFree(source_id_str);
@@ -391,5 +398,6 @@
     PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
     PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
-    PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveFile.file_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveFile.fileset_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-file_id", "receiveFile.file_id", "==");
 
     // optional
@@ -499,2 +507,104 @@
     return true;
 }
+static bool toadvanceMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psMetadata *where = psMetadataAlloc(); // WHERE conditions
+
+    // optional
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+
+    psString query = pxDataGet("receivetool_toadvance.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
+        psFree(where);
+        return false;
+    }
+
+    if (psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+    psFree(where);
+
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
+    if (!p_psDBRunQueryF(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    psArray *output = p_psDBFetchResult(config->dbh);
+    if (!output) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        psTrace("receivetool", PS_LOG_INFO, "No rows found");
+        psFree(output);
+        return true;
+    }
+    if (!ippdbPrintMetadatas(stdout, output, "toadvanceFilesets", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
+        psFree(output);
+        return false;
+    }
+    psFree(output);
+
+    return true;
+}
+
+static bool updatefilesetMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // required
+    PXOPT_LOOKUP_S64(fileset_id, config->args, "-fileset_id", true, false);
+
+    // to chanage
+    PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_STR(dbinfo_uri, config->args, "-dbinfo_uri", false, false);
+    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
+
+    if (!fault && !dbinfo_uri && !state) {
+        psError(PS_ERR_UNKNOWN, true, "one of -fault, -dbinfo_uri, -set_state are required");
+        return false;
+    }
+
+    psString query = NULL;              // Query to execute
+    psStringAppend(&query, "UPDATE receiveFileset SET ");
+    
+    psString sep = "";
+    if (fault) {
+        psStringAppend(&query, "%s fault = %d", sep, fault);
+        sep = ",";
+    }
+    if (dbinfo_uri) {
+        psStringAppend(&query, "%s dbinfo_uri = '%s'", sep, dbinfo_uri);
+        sep = ",";
+    }
+    if (state) {
+        psStringAppend(&query, "%s state = '%s'", sep, state);
+        sep = ",";
+    }
+    
+    psStringAppend(&query, " WHERE fileset_id = %" PRId64, fileset_id);
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    return true;
+}
Index: /trunk/ippTools/src/receivetool.h
===================================================================
--- /trunk/ippTools/src/receivetool.h	(revision 24037)
+++ /trunk/ippTools/src/receivetool.h	(revision 24038)
@@ -30,4 +30,6 @@
     RECEIVETOOL_MODE_UPDATELAST,
     RECEIVETOOL_MODE_PENDINGFILESET,
+    RECEIVETOOL_MODE_UPDATEFILESET,
+    RECEIVETOOL_MODE_TOADVANCE,
     RECEIVETOOL_MODE_ADDFILE,
     RECEIVETOOL_MODE_PENDINGFILE,
Index: /trunk/ippTools/src/receivetoolConfig.c
===================================================================
--- /trunk/ippTools/src/receivetoolConfig.c	(revision 24037)
+++ /trunk/ippTools/src/receivetoolConfig.c	(revision 24038)
@@ -50,4 +50,7 @@
     psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-comment", 0, "define comment", NULL);
     psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-last", 0, "define last fileset", NULL);
+    psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-status_product", 0, "define status_product", NULL);
+    psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-ds_dbname", 0, "define ds_dbname", NULL);
+    psMetadataAddStr(definesourceArgs, PS_LIST_TAIL, "-ds_dbhost", 0, "define ds_dbhost", NULL);
 
     // -list
@@ -74,6 +77,14 @@
     psMetadataAddStr(pendingfilesetArgs, PS_LIST_TAIL, "-product", 0, "search on product", NULL);
     psMetadataAddStr(pendingfilesetArgs, PS_LIST_TAIL, "-comment", 0, "search on comment (LIKE)", NULL);
+    psMetadataAddBool(pendingfilesetArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
     psMetadataAddU64(pendingfilesetArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
-    psMetadataAddBool(pendingfilesetArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
+    psMetadataAddStr(pendingfilesetArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
+
+    // -updatefileset
+    psMetadata *updatefilesetArgs = psMetadataAlloc();
+    psMetadataAddS64(updatefilesetArgs, PS_LIST_TAIL, "-fileset_id", 0, "define fileset_id (required)", 0);
+    psMetadataAddStr(updatefilesetArgs, PS_LIST_TAIL, "-set_state", 0, "define state", NULL);
+    psMetadataAddStr(updatefilesetArgs, PS_LIST_TAIL, "-dbinfo_uri", 0, "define dbinfo_uri", NULL);
+    psMetadataAddS32(updatefilesetArgs, PS_LIST_TAIL, "-fault", 0, "define fault code", 0);
 
     // -addfile
@@ -88,6 +99,8 @@
     psMetadataAddStr(pendingfileArgs, PS_LIST_TAIL, "-comment", 0, "search on comment (LIKE)", NULL);
     psMetadataAddS64(pendingfileArgs, PS_LIST_TAIL, "-fileset_id", 0, "search on fileset_id", 0);
+    psMetadataAddS64(pendingfileArgs, PS_LIST_TAIL, "-file_id", 0, "search on file_id", 0);
     psMetadataAddU64(pendingfileArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
     psMetadataAddBool(pendingfileArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
+    psMetadataAddStr(pendingfileArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
 
     // -addresult
@@ -107,4 +120,13 @@
     psMetadataAddStr(revertArgs, PS_LIST_TAIL, "-comment", 0, "search on comment (LIKE)", NULL);
 
+    // -toadvance
+    psMetadata *toadvanceArgs = psMetadataAlloc();
+    psMetadataAddS64(toadvanceArgs, PS_LIST_TAIL, "-fileset_id", 0, "search on fileset_id", 0);
+    psMetadataAddS64(toadvanceArgs, PS_LIST_TAIL, "-source_id", 0, "search on source_id", 0);
+    psMetadataAddU64(toadvanceArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
+    psMetadataAddBool(toadvanceArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
+    // label is not used but pantasks requires it
+    psMetadataAddStr(toadvanceArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
+
     psMetadata *argSets = psMetadataAlloc();
     psMetadata *modes = psMetadataAlloc();
@@ -114,5 +136,7 @@
     PXOPT_ADD_MODE("-addfileset", "", RECEIVETOOL_MODE_ADDFILESET, addfilesetArgs);
     PXOPT_ADD_MODE("-updatelast", "", RECEIVETOOL_MODE_UPDATELAST, updatelastArgs);
+    PXOPT_ADD_MODE("-updatefileset", "", RECEIVETOOL_MODE_UPDATEFILESET, updatefilesetArgs);
     PXOPT_ADD_MODE("-pendingfileset", "", RECEIVETOOL_MODE_PENDINGFILESET, pendingfilesetArgs);
+    PXOPT_ADD_MODE("-toadvance", "", RECEIVETOOL_MODE_TOADVANCE, toadvanceArgs);
     PXOPT_ADD_MODE("-addfile", "", RECEIVETOOL_MODE_ADDFILE, addfileArgs);
     PXOPT_ADD_MODE("-pendingfile", "", RECEIVETOOL_MODE_PENDINGFILE, pendingfileArgs);
