Index: trunk/ippScripts/scripts/magic_cleanup.pl
===================================================================
--- trunk/ippScripts/scripts/magic_cleanup.pl	(revision 30356)
+++ trunk/ippScripts/scripts/magic_cleanup.pl	(revision 30373)
@@ -37,10 +37,10 @@
 
 # Parse the command-line arguments
-my ($magic_id, $exp_id, $workdir, $camera);
+my ($magic_id, $exp_id, $outroot, $camera);
 my ($dbname, $verbose, $no_update, $no_op, $logfile);
 
 GetOptions(
            'magic_id=s'     => \$magic_id,   # Magic run identifier
-           'workdir=s'      => \$workdir,    # directory to clean up
+           'outroot=s'      => \$outroot,    # directory to clean up
            'camera=s'       => \$camera,    # directory to clean up
            'logfile=s'      => \$logfile,
@@ -54,18 +54,21 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --magic_id --workdir --camera",
+pod2usage( -msg => "Required options: --magic_id --exp_id --outroot --camera",
            -exitval => 3) unless
     defined $magic_id and
-    defined $workdir and 
+    defined $exp_id and
+    defined $outroot and 
     defined $camera;
 
 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $magic_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
+$ipprc->outroot_prepare($outroot);
 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_id, $PS_EXIT_SYS_ERROR ) if $logfile;
 
-if (-e $workdir) {
+my $parentdir = dirname($outroot);
+if (-e $parentdir ) {
     my @extensions = ('.list', '.streakMap', '.streaks', '.clusters', '_hough.fits');
     foreach my $ext (@extensions) {
         my $n = 0;
-        my $path = $workdir . '/*' . $ext;
+        my $path = $outroot . '*' . $ext;
         my @files = glob($path);
         foreach my $file (@files) {
@@ -74,5 +77,5 @@
                 unless ($no_op) {
                     # remove this print
-                    print "unlinking $file\n";
+                    # print "unlinking $file\n";
                     unlink $file or my_die ("unable to delete $file", $magic_id, $PS_EXIT_SYS_ERROR);
                 } else {
@@ -84,5 +87,5 @@
     }
     # remove the verify directory
-    my $verify_dir = $workdir . "/$exp_id.mgc.$magic_id.verify";
+    my $verify_dir = $parentdir . "/$exp_id.mgc.$magic_id.verify";
     if (-e $verify_dir ) {
         my $rc = system "rm -r $verify_dir";
@@ -91,31 +94,27 @@
     }
 } else {
-    # workdir doesn't exist.
-    # If it's parent directory does exist, then assume workdir is gone so it is "cleaned'
-    my $parentdir = dirname($workdir);
-    if (! -e $parentdir ) {
-        # parent directory doesn't exist either, check that mountpoint exists
-        # we expect at least /data/volume
-        my @dirs = split "/", $parentdir;
-        # so the following should be true
-        # $dirs[0] eq ""
-        # $dirs[1] eq 'data'
-        # $dirs[2] eq the volume: for example ipp053.0
-        if ((scalar(@dirs) < 3) or ($dirs[0] ne "") or ($dirs[1] ne 'data')) {
-            my_die("unexpected parent of workdir found: '$parentdir'", $magic_id, $PS_EXIT_UNKNOWN_ERROR);
-        } else { 
-            # re-form mountpoint
-            my $mountpoint = "/$dirs[1]/$dirs[2]";
-            # check if it is readable
-            if (! -e $mountpoint or ! -r $mountpoint ) {
-                my_die("mount point for workdir not found or not readable: '$mountpoint'", $magic_id, $PS_EXIT_SYS_ERROR);
-            }
+    # parent directory doesn't "exist" either, check that mountpoint exists
+    # if it doesn't assume nfs error and fault
+    # we expect at least /data/volume
+    my @dirs = split "/", $parentdir;
+    # so the following should be true
+    # $dirs[0] eq ""
+    # $dirs[1] eq 'data'
+    # $dirs[2] eq the volume: for example ipp053.0
+    if ((scalar(@dirs) < 3) or ($dirs[0] ne "") or ($dirs[1] ne 'data')) {
+        my_die("unexpected parent of outroot found: '$parentdir'", $magic_id, $PS_EXIT_UNKNOWN_ERROR);
+    } else { 
+        # re-form mountpoint
+        my $mountpoint = "/$dirs[1]/$dirs[2]";
+        # check if it is readable
+        if (! -e $mountpoint or ! -r $mountpoint ) {
+            my_die("mount point for outroot not found or not readable: '$mountpoint'", $magic_id, $PS_EXIT_SYS_ERROR);
         }
-        print "Workdir $workdir not found. Setting magicRun.workdir_state to cleaned.\n";
-        # fall through to update workdir_state
     }
+    print "Workdir $outroot not found. Setting magicRun.workdir_state to cleaned.\n";
+    # fall through to update workdir_state
 }
             
-my $command = "$magictool -updaterun -magic_id $magic_id -set_workdir_state cleaned";
+my $command = "$magictool -setworkdirstate -magic_id $magic_id -set_workdir_state cleaned";
 $command   .= " -dbname $dbname" if defined $dbname;
 unless ($no_update) {
@@ -138,5 +137,5 @@
     $exit_code = $PS_EXIT_PROG_ERROR unless $exit_code;
 
-    my $command = "$magictool -updaterun -set_workdir_state error_cleaned";
+    my $command = "$magictool -setworkdirstate -set_workdir_state error_cleaned";
     $command   .= " -magic_id $magic_id";
     $command   .= " -dbname $dbname" if defined $dbname;
