Changeset 30374 for trunk/ippTools/src/magictool.c
- Timestamp:
- Jan 26, 2011, 10:09:06 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magictool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magictool.c
r29625 r30374 49 49 static bool censorrunMode(pxConfig *config); 50 50 static bool exposureMode(pxConfig *config); 51 static bool setgotocleanedMode(pxConfig *config); 52 static bool tocleanupMode(pxConfig *config); 53 static bool setworkdirstateMode(pxConfig *config); 51 54 52 55 static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state, psString setString); … … 89 92 MODECASE(MAGICTOOL_MODE_CENSORRUN, censorrunMode); 90 93 MODECASE(MAGICTOOL_MODE_EXPOSURE, exposureMode); 94 MODECASE(MAGICTOOL_MODE_SETGOTOCLEANED, setgotocleanedMode); 95 MODECASE(MAGICTOOL_MODE_TOCLEANUP, tocleanupMode); 96 MODECASE(MAGICTOOL_MODE_SETWORKDIRSTATE, setworkdirstateMode); 91 97 default: 92 98 psAbort("invalid option (this should not happen)"); … … 1622 1628 return true; 1623 1629 } 1630 static bool setgotocleanedMode(pxConfig *config) 1631 { 1632 PS_ASSERT_PTR_NON_NULL(config, false); 1633 1634 psMetadata *where = psMetadataAlloc(); 1635 PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 1636 PXOPT_COPY_S64(config->args, where, "-exp_id", "magicRun.exp_id", "=="); 1637 PXOPT_COPY_STR(config->args, where, "-label", "magicRun.label", "LIKE"); 1638 PXOPT_COPY_STR(config->args, where, "-data_group", "magicRun.data_group", "LIKE"); 1639 1640 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false); 1641 1642 psString query = psStringCopy("UPDATE magicRun SET workdir_state = 'goto_cleaned'\n"); 1643 if (set_label) { 1644 psStringAppend(&query, ", label = '%s'", set_label); 1645 } 1646 // This mode doubles as a revert function for cleanup errors 1647 PXOPT_LOOKUP_BOOL(clearfault, config->args, "-clearfault", false); 1648 if (!clearfault) { 1649 psStringAppend(&query, "WHERE workdir_state = 'dirty'"); 1650 } else { 1651 psStringAppend(&query, "WHERE workdir_state = 'error_cleaned'"); 1652 } 1653 psStringAppend(&query, "\nAND (magicRun.state = 'full' OR magicRun.state = 'drop')"); 1654 1655 // Require search parameters unless we're just clearing faults 1656 if (psListLength(where->list)) { 1657 psString clause = psDBGenerateWhereConditionSQL(where, NULL); 1658 psStringAppend(&query, "\nAND %s", clause); 1659 psFree(clause); 1660 psFree(where); 1661 } else if ( !clearfault) { 1662 psError(PS_ERR_UNKNOWN, false, "search parameters are required"); 1663 psFree(where); 1664 return false; 1665 } 1666 1667 if (!p_psDBRunQuery(config->dbh, query)) { 1668 psError(PS_ERR_UNKNOWN, false, "database error"); 1669 psFree(query); 1670 return false; 1671 } 1672 psFree(query); 1673 1674 return true; 1675 } 1676 1677 static bool setworkdirstateMode(pxConfig *config) 1678 { 1679 PS_ASSERT_PTR_NON_NULL(config, false); 1680 1681 // required 1682 PXOPT_LOOKUP_S64(magic_id, config->args, "-magic_id", true, false); 1683 PXOPT_LOOKUP_STR(workdir_state, config->args, "-set_workdir_state", true, false); 1684 1685 if (strcmp(workdir_state, "cleaned") && strcmp(workdir_state, "error_cleaned")) { 1686 psError(PS_ERR_UNKNOWN, true, "%s is not a valid value for workdir_state", workdir_state); 1687 return false; 1688 } 1689 1690 psString query = NULL; 1691 psStringAppend(&query, "UPDATE magicRun SET workdir_state = '%s' WHERE magic_id = %" PRId64, workdir_state, magic_id); 1692 1693 if (!p_psDBRunQuery(config->dbh, query)) { 1694 psError(PS_ERR_UNKNOWN, false, "database error"); 1695 psFree(query); 1696 return false; 1697 } 1698 psFree(query); 1699 1700 return true; 1701 } 1702 static bool tocleanupMode(pxConfig *config) 1703 { 1704 PS_ASSERT_PTR_NON_NULL(config, false); 1705 1706 psMetadata *where = psMetadataAlloc(); 1707 PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 1708 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 1709 pxAddLabelSearchArgs (config, where, "-data_group", "magicRun.data_group", "=="); 1710 1711 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1712 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1713 1714 psString query = pxDataGet("magictool_tocleanup.sql"); 1715 if (!query) { 1716 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1717 return false; 1718 } 1719 1720 if (psListLength(where->list)) { 1721 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1722 psStringAppend(&query, " AND %s", whereClause); 1723 psFree(whereClause); 1724 } 1725 psFree(where); 1726 1727 psStringAppend(&query, "\nORDER BY priority DESC, magic_id"); 1728 1729 // treat limit == 0 as "no limit" 1730 if (limit) { 1731 psString limitString = psDBGenerateLimitSQL(limit); 1732 psStringAppend(&query, " %s", limitString); 1733 psFree(limitString); 1734 } 1735 1736 if (!p_psDBRunQuery(config->dbh, query)) { 1737 psError(PS_ERR_UNKNOWN, false, "database error"); 1738 psFree(query); 1739 return false; 1740 } 1741 psFree(query); 1742 1743 psArray *output = p_psDBFetchResult(config->dbh); 1744 if (!output) { 1745 psErrorCode err = psErrorCodeLast(); 1746 switch (err) { 1747 case PS_ERR_DB_CLIENT: 1748 psError(PXTOOLS_ERR_SYS, false, "database error"); 1749 case PS_ERR_DB_SERVER: 1750 psError(PXTOOLS_ERR_PROG, false, "database error"); 1751 default: 1752 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1753 } 1754 1755 return false; 1756 } 1757 if (!psArrayLength(output)) { 1758 psTrace("magictool", PS_LOG_INFO, "no rows found"); 1759 psFree(output); 1760 return true; 1761 } 1762 1763 if (psArrayLength(output)) { 1764 // negative simple so the default is true 1765 if (!ippdbPrintMetadatas(stdout, output, "tocleanup", !simple)) { 1766 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1767 psFree(output); 1768 return false; 1769 } 1770 } 1771 1772 psFree(output); 1773 1774 return true; 1775 }
Note:
See TracChangeset
for help on using the changeset viewer.
