IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 19, 2013, 3:39:39 PM (13 years ago)
Author:
eugene
Message:

merged from trunk

Location:
branches/eam_branches/ipp-20130307/ippTools/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130307/ippTools/src

  • branches/eam_branches/ipp-20130307/ippTools/src/pstamptool.c

    r35350 r35412  
    4949static bool revertjobMode(pxConfig *config);
    5050
    51 # if (1)
    52 // these are unused functions -- since they are 'static', this raises an warning
    53 // XXX: They actually are used
    5451static bool addprojectMode(pxConfig *config);
    5552static bool projectMode(pxConfig *config);
     
    6360static bool listfileMode(pxConfig *config);
    6461static bool deletefileMode(pxConfig *config);
    65 # endif
    6662
    6763# define MODECASE(caseName, func) \
     
    10399        MODECASE(PSTAMPTOOL_MODE_STOPDEPENDENTJOB, stopdependentjobMode);
    104100        MODECASE(PSTAMPTOOL_MODE_REVERTJOB, revertjobMode);
    105 # if (1)
    106101        MODECASE(PSTAMPTOOL_MODE_ADDPROJECT, addprojectMode);
    107102        MODECASE(PSTAMPTOOL_MODE_MODPROJECT, modprojectMode);
     
    115110        MODECASE(PSTAMPTOOL_MODE_LISTFILE, listfileMode);
    116111        MODECASE(PSTAMPTOOL_MODE_DELETEFILE, deletefileMode);
    117 # endif
     112
    118113        default:
    119114            psAbort("invalid option (this should not happen)");
     
    624619    if (outdir) {
    625620        psStringAppend(&query, ", outdir = '%s'", outdir);
     621    }
     622    if (username) {
     623        psStringAppend(&query, ", username = '%s'", username);
    626624    }
    627625    if (clearfault) {
     
    12361234    PXOPT_LOOKUP_BOOL(need_magic, config->args, "-need_magic", false);
    12371235    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
     1236    PXOPT_LOOKUP_BOOL(hold,       config->args, "-hold", false);
    12381237
    12391238    psMetadata *where = psMetadataAlloc();
     
    12431242    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
    12441243
    1245     // start a transaction eraly so it will contain any row level locks
     1244    // start a transaction early so it will contain any row level locks
    12461245    if (!psDBTransaction(config->dbh)) {
    12471246        psError(PS_ERR_UNKNOWN, false, "database error");
     
    12671266        psError(PS_ERR_UNKNOWN, false, "database error");
    12681267        psFree(query);
     1268        if (!psDBRollback(config->dbh)) {
     1269            psError(PS_ERR_UNKNOWN, false, "database error");
     1270        }
    12691271        return false;
    12701272    }
     
    12741276    if (!output) {
    12751277        psError(PS_ERR_UNKNOWN, false, "database error");
     1278        if (!psDBRollback(config->dbh)) {
     1279            psError(PS_ERR_UNKNOWN, false, "database error");
     1280        }
    12761281        return false;
    12771282    }
     
    12821287            psError(PS_ERR_UNKNOWN, false, "database error");
    12831288            psFree(output);
     1289            if (!psDBRollback(config->dbh)) {
     1290                psError(PS_ERR_UNKNOWN, false, "database error");
     1291            }
    12841292            return false;
    12851293        }
     
    12871295        if (fault > 0) {
    12881296            fprintf(stderr, "existing dependent has fault %d\n", fault);
     1297            if (!psDBRollback(config->dbh)) {
     1298                psError(PS_ERR_UNKNOWN, false, "database error");
     1299            }
     1300            // return the fault to the client. This is used by the postage stamp parser
    12891301            exit (fault);
    12901302        }
     1303        bool commit = false;
     1304        // Check the state of the exisiting dependent. By query it is either
     1305        // new or hold
     1306        psString state = psMetadataLookupStr(NULL, dep, "state");
     1307        if (!hold && !strcmp(state, "hold")) {
     1308            // There is a dependent for this component but it's state is hold.
     1309            // This client needs one that will run.
     1310            // Update the state
     1311            psString updateQuery = NULL;
     1312            psStringAppend(&updateQuery, "UPDATE pstampDependent SET state = 'new' "
     1313                "\nWHERE stage = '%s' AND imagedb = '%s' AND stage_id = %"PRId64 " AND component = '%s'",
     1314                    stage, imagedb, stage_id, component);
     1315
     1316            if (!p_psDBRunQuery(config->dbh, updateQuery)) {
     1317                psError(PS_ERR_UNKNOWN, false, "database error");
     1318                psFree(updateQuery);
     1319                if (!psDBRollback(config->dbh)) {
     1320                    psError(PS_ERR_UNKNOWN, false, "database error");
     1321                }
     1322                return false;
     1323            }
     1324            // set flag to commit this change
     1325            commit = true;
     1326            psFree(updateQuery);
     1327        }
     1328        // print the dep_id for the user
    12911329        printf("%" PRId64 "\n", dep_id);
    12921330        psFree(output);
    1293         if (!psDBRollback(config->dbh)) {
     1331        // now either commit the change or rollback the transaction which releases the lock
     1332        if (commit) {
     1333            if (!psDBCommit(config->dbh)) {
     1334                // rollback
     1335                if (!psDBRollback(config->dbh)) {
     1336                    psError(PS_ERR_UNKNOWN, false, "database error");
     1337                }
    12941338            psError(PS_ERR_UNKNOWN, false, "database error");
     1339            return false;
     1340            }
     1341        } else if (!psDBRollback(config->dbh)) {
     1342            psError(PS_ERR_UNKNOWN, false, "database error");
     1343            return false;
    12951344        }
    12961345        return true;
     
    13101359        config->dbh,
    13111360        0,              // dep_id
    1312         "new",          // state
     1361        hold ? "hold" : "new",          // state
    13131362        stage,
    13141363        stage_id,
Note: See TracChangeset for help on using the changeset viewer.