Changeset 29561 for trunk/ippTools/src/magicdstool.c
- Timestamp:
- Oct 26, 2010, 8:39:32 AM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magicdstool.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magicdstool.c
r29358 r29561 39 39 static bool advancerunMode(pxConfig *config); 40 40 static bool revertdestreakedfileMode(pxConfig *config); 41 static bool updatedestreakedfileMode(pxConfig *config); 41 42 static bool clearstatefaultsMode(pxConfig *config); 42 43 static bool getskycellsMode(pxConfig *config); … … 45 46 static bool completedrevertMode(pxConfig *config); 46 47 static bool tocleanupMode(pxConfig *config); 48 static bool tofullfileMode(pxConfig *config); 49 static bool tocleanedfileMode(pxConfig *config); 50 static bool setfiletoupdateMode(pxConfig *config); 47 51 48 52 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psString extraSetString, psMetadata *where, const char *state); … … 73 77 MODECASE(MAGICDSTOOL_MODE_ADVANCERUN, advancerunMode); 74 78 MODECASE(MAGICDSTOOL_MODE_REVERTDESTREAKEDFILE,revertdestreakedfileMode); 79 MODECASE(MAGICDSTOOL_MODE_UPDATEDESTREAKEDFILE,updatedestreakedfileMode); 75 80 MODECASE(MAGICDSTOOL_MODE_CLEARSTATEFAULTS, clearstatefaultsMode); 76 81 MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS, getskycellsMode); … … 79 84 MODECASE(MAGICDSTOOL_MODE_COMPLETEDREVERT, completedrevertMode); 80 85 MODECASE(MAGICDSTOOL_MODE_TOCLEANUP, tocleanupMode); 86 MODECASE(MAGICDSTOOL_MODE_TOFULLFILE, tofullfileMode); 87 MODECASE(MAGICDSTOOL_MODE_TOCLEANEDFILE, tocleanedfileMode); 88 MODECASE(MAGICDSTOOL_MODE_SETFILETOUPDATE, setfiletoupdateMode); 81 89 default: 82 90 psAbort("invalid option (this should not happen)"); … … 558 566 PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false); 559 567 568 if (!strcmp(state, "update")) { 569 fprintf(stderr, "'-updaterun -set_state update' is not supported. Use -setfiletoupdate"); 570 return false; 571 } 572 560 573 // optional 561 574 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false); … … 907 920 return false; 908 921 } 922 923 return true; 924 } 925 static bool updatedestreakedfileMode(pxConfig *config) 926 { 927 PS_ASSERT_PTR_NON_NULL(config, false); 928 929 // required values 930 PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false); 931 PXOPT_LOOKUP_STR(component, config->args, "-component", true, false); 932 933 // default values 934 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 935 PXOPT_LOOKUP_STR(backup_path_base, config->args, "-backup_path_base", false, false); 936 PXOPT_LOOKUP_STR(recovery_path_base, config->args, "-recovery_path_base", false, false); 937 PXOPT_LOOKUP_STR(data_state, config->args, "-data_state", false, false); 938 PXOPT_LOOKUP_F32(streak_frac, config->args, "-streak_frac", false, false); 939 PXOPT_LOOKUP_F32(nondiff_frac, config->args, "-nondiff_frac", false, false); 940 PXOPT_LOOKUP_F32(run_time, config->args, "-run_time", false, false); 941 942 psString query = psStringCopy("UPDATE magicDSFile"); 943 944 945 char *initial_separator = " SET"; 946 char *sep = initial_separator; 947 if (fault) { 948 psStringAppend(&query, "%s fault = %d", sep, fault); 949 sep = ", "; 950 } 951 if (backup_path_base) { 952 psStringAppend(&query, "%s backup_path_base = '%s'", sep, backup_path_base); 953 sep = ", "; 954 } 955 if (recovery_path_base) { 956 psStringAppend(&query, "%s recovery_path_base = '%s'", sep, recovery_path_base); 957 sep = ", "; 958 } 959 if (data_state) { 960 psStringAppend(&query, "%s data_state = '%s'", sep, data_state); 961 sep = ", "; 962 } 963 if (streak_frac) { 964 psStringAppend(&query, "%s streak_frac = '%f'", sep, streak_frac); 965 sep = ", "; 966 } 967 if (nondiff_frac) { 968 psStringAppend(&query, "%s nondiff_frac = '%f'", sep, nondiff_frac); 969 sep = ", "; 970 } 971 if (run_time) { 972 psStringAppend(&query, "%s run_time = '%f'", sep, run_time); 973 sep = ", "; 974 } 975 if (sep == initial_separator) { 976 psFree(query); 977 psError(PS_ERR_UNKNOWN, true, "must set at least one value"); 978 return false; 979 } 980 981 psStringAppend(&query, "\nWHERE magic_ds_id = %" PRId64 " AND component = '%s'\n", magic_ds_id, component); 982 983 if (!p_psDBRunQuery(config->dbh, query)) { 984 psError(PS_ERR_UNKNOWN, false, "database error"); 985 psFree(query); 986 return false; 987 } 988 psFree(query); 909 989 910 990 return true; … … 1019 1099 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "=="); 1020 1100 PXOPT_COPY_STR(config->args, where, "-component", "component", "=="); 1101 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 1021 1102 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 1022 1103 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 1023 1104 1024 psString query = pxDataGet("magicdstool_revertdestreakedfile.sql"); 1105 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 1106 1107 psString queryFile = NULL; 1108 if (state) { 1109 if (! strcmp(state, "new") ) { 1110 queryFile = "magicdstool_revertdestreakedfile.sql"; 1111 } else if (!strcmp(state, "update")) { 1112 queryFile = "magicdstool_revertupdated.sql"; 1113 } else { 1114 psError(PXTOOLS_ERR_SYS, true, "%s is not a valid value for state", state); 1115 return false; 1116 } 1117 } else { 1118 queryFile = "magicdstool_revertdestreakedfile.sql"; 1119 } 1120 psString query = pxDataGet(queryFile); 1121 if (!query) { 1122 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1123 return false; 1124 } 1025 1125 1026 1126 if (psListLength(where->list)) { … … 1241 1341 (strcmp(state, "censored") == 0) || 1242 1342 (strcmp(state, "cleaned") == 0) || 1343 (strcmp(state, "update") == 0) || 1243 1344 (strcmp(state, "goto_restored") == 0) || 1244 1345 (strcmp(state, "goto_censored") == 0) || … … 1520 1621 return true; 1521 1622 } 1623 1624 // update magicDSFile.data_state to given value. 1625 // afterwards, if all files in the magicDSRun have the new state, 1626 // update the state for it as well 1627 // shared code for the modes -tocleanedfile -tofullfile 1628 1629 static bool change_file_data_state(pxConfig *config, psString data_state) 1630 { 1631 PS_ASSERT_PTR_NON_NULL(config, false); 1632 1633 // magic_id, component 1634 PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false); 1635 PXOPT_LOOKUP_STR(component, config->args, "-component", true, false); 1636 1637 psString query = pxDataGet("magicdstool_change_file_data_state.sql"); 1638 1639 if (!psDBTransaction(config->dbh)) { 1640 psError(PS_ERR_UNKNOWN, false, "database error"); 1641 return false; 1642 } 1643 if (!strcmp(data_state, "full")) { 1644 // if -tofullfile optoinally set the magicked value for the component 1645 PXOPT_LOOKUP_BOOL(setmagicked, config->args, "-setmagicked", false); 1646 // set the image file's magicked flag 1647 if (!setMagicked(config, magic_ds_id, component)) { 1648 psError(PS_ERR_UNKNOWN, false, "setMagicked failed"); 1649 if (!psDBRollback(config->dbh)) { 1650 psError(PS_ERR_UNKNOWN, false, "database error"); 1651 } 1652 return false; 1653 } 1654 } 1655 1656 if (!p_psDBRunQueryF(config->dbh, query, data_state, magic_ds_id, component)) { 1657 psFree(query); 1658 psError(PS_ERR_UNKNOWN, false, "database error"); 1659 // rollback 1660 if (!psDBRollback(config->dbh)) { 1661 psError(PS_ERR_UNKNOWN, false, "database error"); 1662 } 1663 psError(PS_ERR_UNKNOWN, false, "database error"); 1664 return false; 1665 } 1666 psFree(query); 1667 if (psDBAffectedRows(config->dbh) < 1) { 1668 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 1669 return false; 1670 } 1671 1672 query = pxDataGet("magicdstool_change_run_state.sql"); 1673 if (!p_psDBRunQueryF(config->dbh, query, data_state, magic_ds_id, data_state)) { 1674 psFree(query); 1675 // rollback 1676 if (!psDBRollback(config->dbh)) { 1677 psError(PS_ERR_UNKNOWN, false, "database error"); 1678 } 1679 psError(PS_ERR_UNKNOWN, false, "database error"); 1680 return false; 1681 } 1682 psFree(query); 1683 1684 if (!psDBCommit(config->dbh)) { 1685 psError(PS_ERR_UNKNOWN, false, "database error"); 1686 return false; 1687 } 1688 1689 return true; 1690 } 1691 static bool tocleanedfileMode(pxConfig *config) 1692 { 1693 return change_file_data_state(config, "cleaned"); 1694 } 1695 static bool tofullfileMode(pxConfig *config) 1696 { 1697 return change_file_data_state(config, "full"); 1698 } 1699 /* 1700 static bool topurgedimfileMode(pxConfig *config) 1701 { 1702 return change_imfile_data_state(config, "purged", "goto_purged"); 1703 } 1704 static bool toscrubbedfileMode(pxConfig *config) 1705 { 1706 return change_file_data_state(config, "scrubbed", "goto_scrubbed"); 1707 } 1708 */ 1709 1710 // a very specfic function to queue a cleaned magicDSFile to be updated 1711 static bool setfiletoupdateMode(pxConfig *config) 1712 { 1713 PS_ASSERT_PTR_NON_NULL(config, NULL); 1714 1715 PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false); 1716 PXOPT_LOOKUP_STR(component, config->args, "-component", false, false); 1717 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 1718 1719 psString query = pxDataGet("magicdstool_setfiletoupdate.sql"); 1720 if (!query) { 1721 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1722 return false; 1723 } 1724 1725 psString setHook = psStringCopy(""); 1726 if (label) { 1727 psStringAppend(&setHook, "\n , magicDSRun.label = '%s'", label); 1728 } 1729 1730 if (component) { 1731 psStringAppend(&query, " AND (magicDSFile.component = '%s')", component); 1732 } 1733 1734 if (!p_psDBRunQueryF(config->dbh, query, setHook, magic_ds_id)) { 1735 psError(PS_ERR_UNKNOWN, false, "database error"); 1736 return false; 1737 } 1738 1739 psFree(setHook); 1740 psFree(query); 1741 1742 return true; 1743 } 1744 1745
Note:
See TracChangeset
for help on using the changeset viewer.
