Index: trunk/ippTools/share/Makefile.am
===================================================================
--- trunk/ippTools/share/Makefile.am	(revision 29611)
+++ trunk/ippTools/share/Makefile.am	(revision 29625)
@@ -213,5 +213,5 @@
 	flatcorr_dropchip.sql \
 	flatcorr_dropcamera.sql \
-	magictool_addmask.sql \
+	magictool_deletemask.sql \
 	magictool_restore_camera.sql \
 	magictool_restore_chip.sql \
@@ -237,4 +237,5 @@
 	magictool_revertnode.sql \
 	magictool_exposure.sql \
+	magictool_setfull.sql \
 	magicdstool_clearstatefaults.sql \
 	magicdstool_change_file_data_state.sql \
Index: trunk/ippTools/share/magictool_deletemask.sql
===================================================================
--- trunk/ippTools/share/magictool_deletemask.sql	(revision 29625)
+++ trunk/ippTools/share/magictool_deletemask.sql	(revision 29625)
@@ -0,0 +1,9 @@
+DELETE magicMask
+FROM magicRun
+    JOIN magicNodeResult USING(magic_id)
+    JOIN magicMask USING(magic_id)
+WHERE
+    magicRun.state = 'new'
+    AND magicNodeResult.node = 'root'
+    AND magicNodeResult.fault != 0
+    AND magicRun.state = 'new'
Index: trunk/ippTools/share/magictool_setfull.sql
===================================================================
--- trunk/ippTools/share/magictool_setfull.sql	(revision 29625)
+++ trunk/ippTools/share/magictool_setfull.sql	(revision 29625)
@@ -0,0 +1,6 @@
+UPDATE
+    magicRun
+SET
+    state = 'full'
+WHERE
+    state != 'full'
Index: trunk/ippTools/src/magictool.c
===================================================================
--- trunk/ippTools/src/magictool.c	(revision 29611)
+++ trunk/ippTools/src/magictool.c	(revision 29625)
@@ -1059,4 +1059,9 @@
     PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
 
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
     if (!magicNodeResultInsert(config->dbh,
                                magic_id,
@@ -1069,4 +1074,33 @@
     }
 
+    if (fault == 0 && !strcmp(node, "root")) {
+        // Set the magicRun state
+        psString query = pxDataGet("magictool_setfull.sql");
+        if (!query) {
+            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            return false;
+        }
+
+        // manually add constraint
+        psStringAppend(&query, " AND magic_id = %" PRId64, magic_id);
+
+        if (!p_psDBRunQuery(config->dbh, query)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            psFree(query);
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            return false;
+        }
+        psFree(query);
+    }
+    if (!psDBCommit(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
     return true;
 }
@@ -1082,25 +1116,43 @@
     pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "==");
 
-    psString query = pxDataGet("magictool_revertnode.sql");
+    if (!psListLength(where->list)) {
+        psError(PS_ERR_UNKNOWN, false, "search parameters are required");
+        psFree(where);
+        return false;
+    }
+    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+    psFree(where);
+
+    // don't need a transaction because it is ok if the first query succeeds
+    // but the second query does not
+    psString query = pxDataGet("magictool_deletemask.sql");
     if (!query) {
         psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
         return false;
     }
-
-    if (psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClause);
+    psStringAppend(&query, " AND %s", whereClause);
+    if (!p_psDBRunQuery(config->dbh, query)) {
         psFree(whereClause);
-    } else {
-        psError(PS_ERR_UNKNOWN, false, "search parameters are required");
-        psFree(where);
-        return false;
-    }
-    psFree(where);
+        psFree(query);
+        psError(PS_ERR_UNKNOWN, false, "failed to delete faulted masks");
+        return false;
+    }
+    psFree(query);
+
+    query = pxDataGet("magictool_revertnode.sql");
+    if (!query) {
+        psFree(whereClause);
+        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+        return false;
+    }
+    psStringAppend(&query, " AND %s", whereClause);
+    psFree(whereClause);
 
     if (!p_psDBRunQuery(config->dbh, query)) {
+        psFree(query);
         psError(PS_ERR_UNKNOWN, false, "failed to revert");
         return false;
     }
+    psFree(query);
 
     psS32 numUpdated = psDBAffectedRows(config->dbh);
@@ -1180,17 +1232,9 @@
     // required
     PXOPT_LOOKUP_S64(magic_id, config->args, "-magic_id", true, false);
+    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false);
 
     // optional
-//    PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false);
-    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false);
     PXOPT_LOOKUP_S32(streaks, config->args, "-streaks", false, false);
-
-    // default values
     PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
-
-    if (!psDBTransaction(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
 
     if (!magicMaskInsert(config->dbh,
@@ -1205,32 +1249,4 @@
             psError(PS_ERR_UNKNOWN, false, "database error");
         }
-        return false;
-    }
-
-    // Set the magicRun state
-    psString query = pxDataGet("magictool_addmask.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
-        if (!psDBRollback(config->dbh)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-        }
-        return false;
-    }
-
-    // manually add constraint
-    psStringAppend(&query, " AND magic_id = %" PRId64, magic_id);
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        if (!psDBRollback(config->dbh)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-        }
-        return false;
-    }
-    psFree(query);
-
-    if (!psDBCommit(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
     }
