Changeset 25423 for trunk/ippTools/src/magicdstool.c
- Timestamp:
- Sep 16, 2009, 5:05:19 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magicdstool.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magicdstool.c
r25419 r25423 40 40 static bool getskycellsMode(pxConfig *config); 41 41 static bool toremoveMode(pxConfig *config); 42 static bool torestoreMode(pxConfig *config);43 42 static bool torevertMode(pxConfig *config); 44 43 static bool completedrevertMode(pxConfig *config); … … 74 73 MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS, getskycellsMode); 75 74 MODECASE(MAGICDSTOOL_MODE_TOREMOVE, toremoveMode); 76 MODECASE(MAGICDSTOOL_MODE_TORESTORE, torestoreMode);77 75 MODECASE(MAGICDSTOOL_MODE_TOREVERT, torevertMode); 78 76 MODECASE(MAGICDSTOOL_MODE_COMPLETEDREVERT, completedrevertMode); … … 401 399 402 400 psMetadata *where = psMetadataAlloc(); 403 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic _ds_id", "==");401 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "=="); 404 402 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 405 403 pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "=="); … … 803 801 PS_ASSERT_PTR_NON_NULL(config, false); 804 802 803 PXOPT_LOOKUP_BOOL(i_am_sure, config->args, "-i_am_sure", true); 804 if (!i_am_sure) { 805 psError(PS_ERR_UNKNOWN, true, "Reverting destreaked files must be done carefully. -i_am_sure is required."); 806 return false; 807 } 808 805 809 psMetadata *where = psMetadataAlloc(); 806 810 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "=="); … … 809 813 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 810 814 811 psString query = p sStringCopy("DELETE FROM magicDSFile USING magicDSFile, magicDSRun WHERE (magicDSRun.magic_ds_id = magicDSFile.magic_ds_id) AND magicDSFile.fault != 0");815 psString query = pxDataGet("magicdstool_revertdestreakedfile.sql"); 812 816 813 817 if (psListLength(where->list)) { … … 815 819 psStringAppend(&query, " AND %s", whereClause); 816 820 psFree(whereClause); 821 } else { 822 psError(PS_ERR_UNKNOWN, true, "search arguments are required"); 823 return false; 817 824 } 818 825 psFree(where); … … 820 827 if (!p_psDBRunQuery(config->dbh, query)) { 821 828 psError(PS_ERR_UNKNOWN, false, "failed to revert"); 822 return false; 823 } 829 psFree(query); 830 return false; 831 } 832 psFree(query); 824 833 return true; 825 834 } … … 891 900 } 892 901 char *query2 = "UPDATE magicDSRun SET state = '%s' WHERE magic_ds_id = %" PRId64; 893 if (!p_psDBRunQueryF(config->dbh, query2, magic_ds_id, new_state)) {902 if (!p_psDBRunQueryF(config->dbh, query2, new_state, magic_ds_id)) { 894 903 psError(PS_ERR_UNKNOWN, false, "failed to set run magicDSRun.state to %s", new_state); 895 904 return false; … … 971 980 972 981 // check that state is a valid string value 973 if (!( 974 (strncmp(state, "new", 4) == 0) 975 || (strncmp(state, "full", 5) == 0) 976 ) 977 ) { 982 if (!((strcmp(state, "new") == 0) || 983 (strcmp(state, "full") == 0) || 984 (strcmp(state, "restored") == 0) || 985 (strcmp(state, "censored") == 0) || 986 (strcmp(state, "purged") == 0) || 987 (strcmp(state, "goto_restored") == 0) || 988 (strcmp(state, "goto_censored") == 0) || 989 (strcmp(state, "goto_purged") == 0)) 990 ) { 978 991 psError(PS_ERR_UNKNOWN, false, 979 992 "invalid magicDSRun state: %s", state); … … 1064 1077 return true; 1065 1078 } 1066 static bool torestoreMode(pxConfig *config) 1079 1080 static bool torevertMode(pxConfig *config) 1067 1081 { 1068 1082 PS_ASSERT_PTR_NON_NULL(config, false); 1069 1083 1070 1084 psMetadata *where = psMetadataAlloc(); 1085 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 1086 1071 1087 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 1072 1088 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1073 pxAddLabelSearchArgs (config, where, "-label", " label", "==");1089 pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "=="); 1074 1090 1075 1091 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1076 1092 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1077 1093 1078 // look for "inputs" that need to processed 1079 psString query = pxDataGet("magicdstool_torestore.sql"); 1094 psString sql_file = NULL; 1095 psStringAppend(&sql_file, "magicdstool_torevert_%s.sql", stage); 1096 1097 psString query = pxDataGet(sql_file); 1080 1098 if (!query) { 1081 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1082 return false; 1083 } 1099 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", sql_file); 1100 psFree(sql_file); 1101 return false; 1102 } 1103 psFree(sql_file); 1084 1104 1085 1105 if (psListLength(where->list)) { 1086 1106 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1087 psStringAppend(&query, " WHERE%s", whereClause);1107 psStringAppend(&query, " AND %s", whereClause); 1088 1108 psFree(whereClause); 1089 1109 } … … 1126 1146 if (psArrayLength(output)) { 1127 1147 // negative simple so the default is true 1128 if (!ippdbPrintMetadatas(stdout, output, "torestore", !simple)) {1129 psError(PS_ERR_UNKNOWN, false, "failed to print array");1130 psFree(output);1131 return false;1132 }1133 }1134 1135 psFree(output);1136 1137 return true;1138 }1139 1140 1141 static bool torevertMode(pxConfig *config)1142 {1143 PS_ASSERT_PTR_NON_NULL(config, false);1144 1145 psMetadata *where = psMetadataAlloc();1146 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);1147 1148 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");1149 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");1150 pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "==");1151 1152 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);1153 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);1154 1155 psString sql_file = NULL;1156 psStringAppend(&sql_file, "magicdstool_torevert_%s.sql", stage);1157 1158 psString query = pxDataGet(sql_file);1159 if (!query) {1160 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", sql_file);1161 psFree(sql_file);1162 return false;1163 }1164 psFree(sql_file);1165 1166 if (psListLength(where->list)) {1167 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);1168 psStringAppend(&query, " AND %s", whereClause);1169 psFree(whereClause);1170 }1171 psFree(where);1172 1173 // treat limit == 0 as "no limit"1174 if (limit) {1175 psString limitString = psDBGenerateLimitSQL(limit);1176 psStringAppend(&query, " %s", limitString);1177 psFree(limitString);1178 }1179 1180 if (!p_psDBRunQuery(config->dbh, query)) {1181 psError(PS_ERR_UNKNOWN, false, "database error");1182 psFree(query);1183 return false;1184 }1185 psFree(query);1186 1187 psArray *output = p_psDBFetchResult(config->dbh);1188 if (!output) {1189 psErrorCode err = psErrorCodeLast();1190 switch (err) {1191 case PS_ERR_DB_CLIENT:1192 psError(PXTOOLS_ERR_SYS, false, "database error");1193 case PS_ERR_DB_SERVER:1194 psError(PXTOOLS_ERR_PROG, false, "database error");1195 default:1196 psError(PXTOOLS_ERR_PROG, false, "unknown error");1197 }1198 1199 return false;1200 }1201 if (!psArrayLength(output)) {1202 psTrace("magicdstool", PS_LOG_INFO, "no rows found");1203 psFree(output);1204 return true;1205 }1206 1207 if (psArrayLength(output)) {1208 // negative simple so the default is true1209 1148 if (!ippdbPrintMetadatas(stdout, output, "torevert", !simple)) { 1210 1149 psError(PS_ERR_UNKNOWN, false, "failed to print array");
Note:
See TracChangeset
for help on using the changeset viewer.
