Index: trunk/ippTools/src/magictool.c
===================================================================
--- trunk/ippTools/src/magictool.c	(revision 29553)
+++ 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;
     }
