Changeset 10021
- Timestamp:
- Nov 16, 2006, 2:23:19 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pzgetimfiles.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pzgetimfiles.c
r10014 r10021 36 36 int main(int argc, char **argv) 37 37 { 38 psLibInit(NULL); 39 38 40 pxConfig *config = pzgetimfilesConfig(NULL, argc, argv); 39 41 … … 43 45 44 46 psFree(config); 47 pmConfigDone(); 48 psLibFinalize(); 49 45 50 exit(EXIT_SUCCESS); 46 51 47 52 FAIL: 48 53 psFree(config); 54 pmConfigDone(); 55 psLibFinalize(); 49 56 50 57 exit(EXIT_FAILURE); 51 58 } 52 59 53 static bool go (pxConfig *config)60 static bool go(pxConfig *config) 54 61 { 55 62 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 74 81 psError(PS_ERR_UNKNOWN, true, "-filesetid is required"); 75 82 return false; 83 } 84 85 psString camera = psMetadataLookupStr(&status, config->args, "-inst"); 86 if (!status) { 87 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst"); 88 return NULL; 89 } 90 if (!camera) { 91 psError(PS_ERR_UNKNOWN, true, "-inst is required"); 92 return NULL; 93 } 94 95 psString telescope = psMetadataLookupStr(&status, config->args, "-telescope"); 96 if (!status) { 97 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope"); 98 return NULL; 99 } 100 if (!telescope) { 101 psError(PS_ERR_UNKNOWN, true, "-telescope is required"); 102 return NULL; 76 103 } 77 104 … … 80 107 psStringAppend(&cmd, "%s --uri %s", FILESET_LS_CMD, uri); 81 108 82 // XXX debugging 83 fprintf(stderr, "cmd is: %s\n", cmd); 109 psTrace("pzgetimfiles", PS_LOG_INFO, "cmd is: %s\n", cmd); 84 110 85 111 FILE *output = popen(cmd, "r"); … … 108 134 return false; 109 135 } 110 111 136 psFree(cmdOutput); 112 137 138 // save the number of new Imfiles; 139 long imfiles = psArrayLength(newImfiles); 140 141 // if the fileset was empty (no files) then we can bail out early 142 if (imfiles == 0) { 143 char *query = 144 "UPDATE summitExp" 145 " SET imfiles = %d" 146 " WHERE exp_id = '%s'" 147 " AND camera = '%s'" 148 " AND telescope = '%s'"; 149 if (!p_psDBRunQuery(config->dbh, query, imfiles, filesetid, camera, telescope)) { 150 psError(PS_ERR_UNKNOWN, false, "database error"); 151 return false; 152 } 153 psFree(newImfiles); 154 return true; 155 } 156 113 157 // start a transaction so it's all rows or nothing 114 158 if (!psDBTransaction(config->dbh)) { … … 125 169 126 170 if (!p_psDBRunQuery(config->dbh, query)) { 171 // rollback 172 if (!psDBRollback(config->dbh)) { 173 psError(PS_ERR_UNKNOWN, false, "database error"); 174 } 127 175 psError(PS_ERR_UNKNOWN, false, "database error"); 128 176 psFree(newImfiles); … … 136 184 long inserted = p_psDBRunQueryPrepared(config->dbh, newImfiles, query); 137 185 if (inserted < 0) { 186 // rollback 187 if (!psDBRollback(config->dbh)) { 188 psError(PS_ERR_UNKNOWN, false, "database error"); 189 } 138 190 psError(PS_ERR_UNKNOWN, false, "database error"); 139 191 psFree(newImfiles); … … 142 194 // sanity check that we actually inserted something 143 195 if (inserted == 0) { 196 // rollback 197 if (!psDBRollback(config->dbh)) { 198 psError(PS_ERR_UNKNOWN, false, "database error"); 199 } 144 200 psError(PS_ERR_UNKNOWN, false, "database error -- we should have inserted at least one row"); 145 201 psFree(newImfiles); … … 148 204 } 149 205 150 // save the number of new Imfiles;151 long imfiles = psArrayLength(newImfiles);152 206 psFree(newImfiles); 207 153 208 { 154 209 char *query = … … 174 229 175 230 if (!p_psDBRunQuery(config->dbh, query)) { 231 // rollback 232 if (!psDBRollback(config->dbh)) { 233 psError(PS_ERR_UNKNOWN, false, "database error"); 234 } 176 235 psError(PS_ERR_UNKNOWN, false, "database error"); 177 236 return false; … … 203 262 204 263 if (!p_psDBRunQuery(config->dbh, query)) { 264 // rollback 265 if (!psDBRollback(config->dbh)) { 266 psError(PS_ERR_UNKNOWN, false, "database error"); 267 } 205 268 psError(PS_ERR_UNKNOWN, false, "database error"); 206 269 return false; … … 210 273 // update summitExp.imfiles 211 274 { 212 char *query = "UPDATE summitExp SET imfiles = %d"; 213 if (!p_psDBRunQuery(config->dbh, query, imfiles)) { 275 char *query = 276 "UPDATE summitExp" 277 " SET imfiles = (SELECT COUNT(*) FROM summitImfile" 278 " WHERE exp_id = '%s'" 279 " AND camera = '%s'" 280 " AND telescope = '%s'" 281 ")" 282 " WHERE exp_id = '%s'" 283 " AND camera = '%s'" 284 " AND telescope = '%s'"; 285 if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope, filesetid, camera, telescope)) { 214 286 psError(PS_ERR_UNKNOWN, false, "database error"); 215 287 return false; … … 271 343 psString line; 272 344 while ((line = psListGetAndIncrement(lineCursor))) { 345 psTrace("pzgetimfiles", PS_LOG_INFO, "parsing line: %s\n", line); 346 273 347 // split line into tokens 274 348 psList *tokens = psStringSplit(line, " ", false); … … 355 429 } 356 430 431 // must be freed after the new metadata is built -- holds the strings 357 432 psFree(tokenCursor); 358 433 psFree(tokens); 359 434 435 // debugging 436 if (psTraceGetLevel("pzgetimfiles") == PS_LOG_INFO) { 437 psString doc = psMetadataConfigFormat(md); 438 psTrace("pzgetimfiles", PS_LOG_INFO, "parsed line as:\n %s\n", doc); 439 psFree(doc); 440 } 441 360 442 psArrayAdd(pzPendingImfiles, 0, md); 361 psMetadataConfigPrint(stdout, md); 443 444 psFree(md); 362 445 } 363 446
Note:
See TracChangeset
for help on using the changeset viewer.
