Index: trunk/ippScripts/scripts/magic_destreak_revert.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak_revert.pl	(revision 24686)
+++ trunk/ippScripts/scripts/magic_destreak_revert.pl	(revision 24726)
@@ -70,7 +70,4 @@
     defined $outroot;
 
-# XXX: for testing
-$no_update = 1;
-
 &my_die("bytes and md5sum are is required for raw stage stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if ($stage eq 'raw' and (!$bytes or !$md5sum));
 
@@ -87,5 +84,4 @@
 if ($@ or not defined $nebulous) {
     &my_die ("Unable to create a Nebulous::Client object with proxy $nebulousServer", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
-    return undef;
 }
 
@@ -109,9 +105,4 @@
 my $nebulousInput = inNebulous($dirname);
 
-# parse replace arguments check for errors and set up
-# the appropriate paths
-# this program doesn't make sense if $replace is false
-&my_die("Invalid value for replace: $replace", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if $replace ne "T";
-
 if (defined($replace) and ($replace eq "T")) {
     $replace = 1;
@@ -120,5 +111,9 @@
 }
 
-# default value is "NULL" do not use
+&my_die("replace not allowed for non-nebulous files", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) 
+    if ($replace eq "T") and !$nebulousInput;
+
+
+# default value is "NULL" do not use it
 if (defined($recoveryroot) and ($recoveryroot eq "NULL")) {
     $recoveryroot = undef;
@@ -135,5 +130,5 @@
     $backup_path_base = $tmproot . "$basename";
 } else {
-    # note: trailing / is necessary
+    # note: the trailing / here is necessary
     $tmproot = "$outroot/";
     $backup_path_base = $tmproot . $basename;
@@ -189,40 +184,44 @@
 }
 
-do_swap($image, $bimage) or
+revert_file($image, $bimage) or
         &my_die("failed to restore image file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
+
+# don't commit next the next couple of lines and see xxx below
+# change to if 0 to revert chip runs without masks
+if (0) {
+
 if ($mask) {
-    my $swap_result = do_swap($mask, $bmask);
-    if (! $swap_result) {
-        # delete next 5 lines
-        if ($stage eq "chip") {
-            # XXX: this is a kludge to get around my test environment
-            # Don't commit
-            print STDERR "failed to resotre camera mask file, proceeding\n";
+    if (!revert_file($mask, $bmask)) {
+        if ($stage eq 'chip') {
+            # XXX: don't fail if the mask file fails to revert. It probably doesn't exist
+            # Handle this properly
+            print STDERR "failure to revert mask file, ignored\n";
         } else {
-        &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
-        }  # delete this line
-    }
-}
+            &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
+        }
+    }
+}
+
 if ($ch_mask) {
-    do_swap($ch_mask, $bch_mask) or
-        &my_die("failed to restore chip mask", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
+    # Handle this properly
+    if (!revert_file($ch_mask, $bch_mask)) {
+        # print STDERR "failure to revert chip mask file, ignored\n";
+        &my_die("failed to restore chip mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
+    }
 } 
+
+# xxx don't commmit next line
+}
+
 if ($weight) {
-    do_swap($weight, $bweight) or
+    revert_file($weight, $bweight) or
         &my_die("failed to restore variance image", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
 }
 
-# now reverse the desreaked file
-# Change magicdstool to set the magicked value to zero
-# Actually we should probably do this first to insure that no data gets deleted
-# Input result into database
-if (0) {
-    # XXX: this is the wrong mode
-    my $command = "$magicdstool -adddestreakedfile";
+# now revert the row in the database
+{
+    my $command = "$magicdstool -revertdestreakedfile";
     $command   .= " -magic_ds_id $magic_ds_id";
     $command   .= " -component $component";
-    $command   .= " -setmagicked" if $replace;
-    $command   .= " -backup_path_base $backup_path_base" if $backup_path_base;
-    $command   .= " -recovery_path_base $recovery_path_base" if $recovery_path_base;
     $command   .= " -dbname $dbname" if defined $dbname;
 
@@ -242,5 +241,4 @@
 
 
-
 ### Pau.
 
@@ -256,5 +254,5 @@
 }
 
-sub do_swap
+sub revert_file
 {
     my $original = shift;
@@ -297,5 +295,5 @@
         if ($b_path and -e $b_path) {
             print "ready to delete backup\n" if $verbose;
-            if (! $nebulous->delete($backup)) {
+            if (! $ipprc->file_delete($backup)) {
                 print "failed to delete $backup\n";
                 return 0;
@@ -307,5 +305,5 @@
         # delete the 'backup' (destreaked target) file if it exists
         if ($b_path and -e $b_path) {
-            if (! $nebulous->delete($backup)) {
+            if (! $ipprc->file_delete($backup)) {
                 print "failed to delete $backup\n";
                 return 0;
@@ -348,20 +346,21 @@
     $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
 
-    my $command = "$magicdstool -adddestreakedfile";
-    $command   .= " -magic_ds_id $magic_ds_id";
-    $command   .= " -component $component";
-    $command   .= " -fault $exit_code";
-    $command   .= " -dbname $dbname" if defined $dbname;
-
-    # Add the processed file to the database
-    unless ($no_update) {
-        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => $verbose);
-        unless ($success) {
-            carp("failed to update database for $magic_ds_id $component");
-        }
-    } else {
-        print "Skipping command: $command\n";
-    }
+    # we wouldn't be here unless an entry already exists in the database
+#    my $command = "$magicdstool -adddestreakedfile";
+#    $command   .= " -magic_ds_id $magic_ds_id";
+#    $command   .= " -component $component";
+#    $command   .= " -fault $exit_code";
+#    $command   .= " -dbname $dbname" if defined $dbname;
+
+#    # Add the processed file to the database
+#    unless ($no_update) {
+#        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+#            run(command => $command, verbose => $verbose);
+#        unless ($success) {
+#            carp("failed to update database for $magic_ds_id $component");
+#        }
+#    } else {
+#        print "Skipping command: $command\n";
+#    }
 
     carp($msg);
